0
点赞
收藏
分享

微信扫一扫

vue组件通信中央事件总线:$bus

梦想家们 2022-03-12 阅读 77

1.全局事件总线$bus配置:


Vue.prototype.$event = this;

// moduleA.vue // 发送数据
methods: {
    sendData () {
        // 通过修改Vue原型链的方式注册
        this.$event.$emit('sendSata', "冬雨");
        // 直接注册在window上

    }

moduleB.vue //接受数据
mounted(){
  this.$event.$on('sendSata',  data=>{
  this.name = data;
}
举报

相关推荐

0 条评论