main.js掛載
Vue.prototype.$bus = new Vue();
a.vue發送
_this.$bus.$emit("openSearch",{data:true})
b.vue接收
created() {
this.$bus.$on("openSearch",d=>{
console.log("搜索已經接收!===>",d.data);
this.showSearch = d.data;
})
},
beforDestroy(){
this.$bus.$off("openSearch");// 當這個組件銷燬的時候bus也跟着一起銷燬
}