Vue 中Bus使用

  • 使用:兄弟组件之间传值;
  • 安装: npm install vue-bus
  • 在main.js 中引入vuebus:
import Vue from 'vue';
import VueBus from 'vue-bus';

Vue.use(VueBus);

 

在组件中使用 javascript

触发事件:vue

this.$bus.emit("onslected",params)
应对事件:
mounted:function(){
this.$bus.on("onslected",function(){

});
},
destroyed:function(){
this.$bus.off("onslected");
}
相关文章
相关标签/搜索