将Bus注入到Vue根对象中,
// main.js
import Vue from 'vue'
Vue.prototype.$bus = new Vue();
组件一中注册事件
created () {
this.bus.$on('busEvent', this.getdata);
}
// 离开时 记得注销事件
beforeDestroy () {
this.bus.$off('busEvent');
}
组件二中调用组件一中的事件
this.bus.$emit('busEvent', data);