组件间简单通信使用空的实例:
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;
});
}
最后发现能够监听到更新的数据,但是数据未渲染,请问这个如何解决?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
把 this 改为 app 应该就可以了吧