组件间简单通信使用空的实例:var app = new Vue();然后组件1触发app.$emit:methods: {linkToDoing: function () { this.isToDoing = true; this.store.isToDoing = this.isToDoing; this.store.selectIndex = 0;
app.$emit('store', this.store);
},} 组件2监听触发的事件app.$on:created: function () {app.$on('store', function (data) { this.title = data.arrTitle[data.selectIndex];
console.log('监听到了', this.title); this.store = data;
});}最后发现能够监听到更新的数据,但是数据未渲染,请问这个如何解决?
1 回答

吃鸡游戏
TA贡献1829条经验 获得超7个赞
把 this 改为 app 应该就可以了吧
app.$on('store', function (data) { app.title = data.arrTitle[data.selectIndex]; console.log('监听到了', app.title); app.store = data; });
添加回答
举报
0/150
提交
取消