文中工具皆可关注 皓月当空w 公众号 发送关键字 工具 获取
使用pubsub-js库,可以让两个任意的组件进行消息通信
npm install pubsub-js
PubSub.subscribe('aab',(_,data) => {
console.log(data);
}
PubSub.publish('aab',{name:'tom',age:18})
componentWillUnmount(){
PubSub.unsubscribe(this.token)
}
componentDidMount(){
this.token = PubSub.subscribe('aab',(_,data) => {
this.setState(data)
}
)
}
componentWillUnmount(){
PubSub.unsubscribe(this.token)
}
欢迎大家关注我朋友的公众号 皓月当空w 分享漏洞情报以及各种学习资源,技能树,面试题等。
以上