vue-pos : 子组件与子组件通讯
阅读原文时间:2023年10月14日阅读:1

子组件与子组件通讯:
例子子组件1 要与子组件2 通讯

  步骤1 : 在父组件新建一个 vue 对象 : const eventHub = new Vue()

  步骤2 : 子组件1 发起事件 :this.$root.eventHub.$emit('cart.add', event.target) ;
      cart.add事件名称 , event.target 事件参数

  步骤3 : 子组件2接受事件,做出相应:
    created() {
      this.$root.eventHub.$on('cart.add', this.drop)
    },
    methods: {
      drop(el) {

        …..做点什么
      }
    }

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章