vue中EventBus使用

第一步,在main.js中定义eventbus

Vue.prototype.$eventHub = Vue.prototype.$eventHub || new Vue()

第二步,需要接收的页面监听和销毁

methods: {
  updateConifg() {
    // 操作
  }
},
mounted() {
this.$eventHub.$on('updateConfig',this.updateConfig) }, destroyed() { this.$eventHub.$off('updateConfig') }

第三步,需要触发监听的页面

this.$eventHub.$emit('updateConfig');
原文地址:https://www.cnblogs.com/chenwan1218/p/15136225.html