步骤一:main.js
new Vue({
beforeCreated(){
//全局事件总监
Vue.prototype.$bus = this
}
})
//监听地方回调
this.$bus.$on('监听的名字',(data) => {
//这里是获取到监听数据
页面卸载的时候使用$off
this.$bus.$off('监听的名字')
this.$bus.$emit('事件的名字',传递的数据)