猿问

如何使用vue中的$on更新data数据并渲染?

组件间简单通信使用空的实例:

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;
});

}
最后发现能够监听到更新的数据,但是数据未渲染,请问这个如何解决?


宝慕林4294392
浏览 2191回答 1
1回答

吃鸡游戏

把 this 改为 app 应该就可以了吧app.$on('store', function (data) {     app.title = data.arrTitle[data.selectIndex];     console.log('监听到了', app.title);     app.store = data; });
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答