你甚至可以使其更短,并将根 Vue实例用作全局事件中心:
组件1:
this.$root.$emit('eventing', data);
组件2:
mounted() {
this.$root.$on('eventing', data => {
console.log(data);
});
}
VueJs 2.0中同级组件之间的通信
你甚至可以使其更短,并将根 Vue实例用作全局事件中心:
组件1:
this.$root.$emit('eventing', data);
组件2:
mounted() {
this.$root.$on('eventing', data => {
console.log(data);
});
}