1 订阅消息
import PubSub from 'pubsub-js'
componentDidMount(){
this.token = PubSub.subscribe('GET_MESSAGE',(msg,data)=>{//订阅消息
this.setState(data)
})
}
componentWillUnmount(){
PubSub.unsubscribe(this.token)
}
2 发布消息
import PubSub from 'pubsub-js'
PubSub.publish('GET_MESSAGE',{isFirst:false,isLoading:true})//发布消息