兄弟組件傳值

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也跟着一起銷燬
	}
發佈了190 篇原創文章 · 獲贊 10 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章