1.在main.js中注册全局的bus
Vue.prototype.bus=new Vue();
2.在组件中使用
// 子组建使用:this.bus.$emit('自定义事件名',实参)
methods:{
handleClick(){
this.bus.$emit('openMenu',true)
}
}
// 父组建使用:this.bus.$on("自定义事件名", msg => {})
mounted() {
this.bus.$on("openMenu", msg => {
this.show = msg;
});
}