- 使用:兄弟組件之間傳值;
- 安裝:
npm install vue-bus
- 在main.js 中引入vuebus:
import Vue from 'vue'; import VueBus from 'vue-bus'; Vue.use(VueBus);
在組件中使用
觸發事件:
this.$bus.emit("onslected",params)
應對事件:
mounted:function(){
this.$bus.on("onslected",function(){
});
},
destroyed:function(){
this.$bus.off("onslected");
}