0
在嵌套对象中,我的组件中的计算属性没有很好地跟踪更改,因此计算属性未按预期触发。相反,我想在父母身上触发它。从根触发子方法(或计算属性) - vue2
什么是执行方法的正确方法,最好是从我的根计算出来的方法?
我尝试使用
this.$emit('updated');
根法
this.$parent.$on('updated', this.organise);
,赶上像这样,
但这返回我一个错误:
Error in event handler for "updated": "TypeError: Cannot read property 'apply' of undefined"
更新:
Vue.prototype.globalEvents = new Vue();
var app = new Vue({
el: '#root',
methods: {
x() {
this.globalEvents.$emit('updated');
}
}
})
Vue.component('x', {
created() {
this.globalEvents.$on('updated', this.doStuff);
}
})
仍然给了我同样的错误
我使用从cdn进行的内联脚本导入:/我还根据您提到的内容更新了我的问题。我是否需要更多步骤才能运作? – senty