该方法使用一个空的Vue实例作为中央事件总线(eventcenter),并用它来触发事件和监听事件。它巧妙、轻量级地实现了任意组件之间的通信,包括父子、兄弟、跨级。当我们的项目比较大的时候,可以选择比较好的状态管理方案vuex。首先新建一个eventBus.jsimportVuefrom'vue'consteventBus=newVue()exportdefault{install(target,options){target.prototype.$eventBus=eventBus}}然后全局注册importeventBusfrom'./utils/eventBus'Vue.use(eventBus);A组件>B组件>C组件示例:A组件打开B组件,然后从B组件打开C组件,然后C组件中的方法触发A组件中的数据更新//Acreated(){this.$eventBus.$on('updateAccount',(data)=>{console.log('bus')this.customerAccountLoad()})},methods:{showDialogB(){this.isShow=true},}//Bmethods:{showDialogC(){this.isShow=true},}//Cupdate(){this.$eventBus.$emit('updateAccount',data)}$on监听自定义事件updateAccount,因为有时候不确定事件什么时候触发,一般在mounted或者createdhook中监听。这样就实现了A组件中的数据更新,无需逐层向上传递。更多通讯方式:https://segmentfault.com/a/1190000019208626