【发布时间】:2018-04-17 00:18:57
【问题描述】:
我无法从组件调用 mixin 方法,我收到此错误this.hello is not a function。
我可以从 Vue 实例调用hello(),但我不能在组件中调用它。
怎么了?!
<div id='vue-app'>
<cmp></cmp>
</div>
const mixin = {
methods: {
hello() {
return 'Hello World!';
}
},
created() {
console.log('Mixin Created!');
},
};
const cmp = {
created() {
console.log('From Cmp:', this.hello());
},
};
new Vue({
components: {
cmp
},
el: '#vue-app',
mixins: [mixin],
created() {
console.log('From VM:', this.hello());
},
});
【问题讨论】: