vue 里bus的使用

兄弟组件之间进行传值(非父子组件);


安装: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")

}

 
 

本文来自博客园,作者:喆星高照,转载请注明原文链接:https://www.cnblogs.com/houxianzhou/p/13541585.html

原文地址:https://www.cnblogs.com/houxianzhou/p/13541585.html