1

Is it possible what I am trying to achieve here to use a value from an object as a method name?

This works great:

Vue.mixin({
  methods: {
    name: function () {
      console.log('hello')
    }
  }
});

But this:

options = {
  methodName: 'name'
};

const method = options.methodName;

Vue.mixin({
  methods: {
    method: function () {
      console.log('hello')
    }
  }
});

Gives me the following error:

Property or method "name" is not defined on the instance but referenced during render.

1 Answer 1

2
Vue.mixin({
  methods: {
    [method]: function () {
      console.log('hello')
    }
  }
});

will work. And you can spare assigning a constant by using

methods: {
  [options.methodName]: function() {...}
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.