您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页什么是消息订阅和发布?

什么是消息订阅和发布?

来源:华佗小知识


(1)介绍

话不多少,上图

下面给出一个例子的主要代码:

(2)消息订阅 

子组件1

  mounted() {
    this.pubId = pubsub.subscribe("haha", function (msgName, data) {
      console.log("有人发步了haha消息,回调函数被执行了", msgName, data);
    });
  },
  beforeDestroy() {
    pubsub.unsubscribe(this.pubId);
  },

(3)消息发布

子组件2

  methods: {
    sendStudentName() {
      // this.getStudentName(this.studentName);
      pubsub.publish("haha", this.studentName);
    },
  },

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务