Publication de messages et abonnement en réaction

Importez d'abord la bibliothèque appropriée

PubSubJS

npm install pubsub-js
//在需要的地方引入
import PubSub from 'pubsub-js'

abonnement aux nouvelles

//msg为消息的名称,data为传过来的数据
var mySubscriber = function (msg, data) {
    
    
    console.log( msg, data );
};
//token为返回值,后续可用来取消订阅
var token = PubSub.subscribe('MY TOPIC', mySubscriber);

communiqué de presse

PubSub.publish('MY TOPIC', 'hello world!');

Je suppose que tu aimes

Origine blog.csdn.net/weixin_44162077/article/details/129660454
conseillé
Classement