Javascript Vue使用对象值作为方法名称
我在这里试图实现的是使用对象的值作为方法名吗 这非常有效:Javascript Vue使用对象值作为方法名称,javascript,vue.js,Javascript,Vue.js,我在这里试图实现的是使用对象的值作为方法名吗 这非常有效: Vue.mixin({ methods: { name: function () { console.log('hello') } } }); 但这是: options = { methodName: 'name' }; const method = options.methodName; Vue.mixin({ methods: { method: function () {
Vue.mixin({
methods: {
name: function () {
console.log('hello')
}
}
});
但这是:
options = {
methodName: 'name'
};
const method = options.methodName;
Vue.mixin({
methods: {
method: function () {
console.log('hello')
}
}
});
给我以下错误:
属性或方法“name”未在实例上定义,但在渲染期间被引用
会有用的。您可以使用
methods: {
[options.methodName]: function() {...}
}
methods: {
[options.methodName]: function() {...}
}