Vue组件之间传值,使用全局 bus 在 Vue 的兄弟组件中传值

1、创建Vue实例

//main.js
Vue.prototype.$bus = new Vue()

2、发射事件

let value='123';
this.$bus.$emit('blurEvent',value);

3、监听事件

this.$bus.$on("blurEvent",(value)=>{
    
    
  console.log(value)
})

4、注销事件

 this.$bus.$off('blurEvent')

猜你喜欢

转载自blog.csdn.net/weixin_46054723/article/details/130532114
今日推荐