使用:兄弟組件之間進行傳值;
安裝:npm install vue-bus
在main.js中引入vue-bus
import Vue from 'vue';
import VueBus from 'vue-bus';
Vue.use(VueBus);
在組件中使用:
A組件觸發事件:
this.$bus.emit("parameterName",params);
B組件接收事件:
this.$bus.on("parameterName",function(value){
console.log(value)
});
組件銷毀時解除事件綁定:
destroyed:function(){
this.$bus.off("parameterName")
}