Vue全局事件总线 前端小西几 2022-07-16 103 阅读1分钟 main.js import Vue from 'vue'; import App from './App.vue'; new Vue({ el:"#app", render: h => h(App), beforeCreate(){ Vue.prototype.$bus = this; } }) 组件事件中接收事件 this.$bus.$on('xxx',this.demo) 发送事件 this.$bus.$emit('xxx',数据)