Vue 中Bus使用

  • 使用:兄弟组件之间传值;
  • 安装: 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");
}
 



原文地址:https://www.cnblogs.com/yanwuming/p/10512905.html