我在一个页面上运行了两个解耦组件,并且希望在单击一个到另一个时使用 Postal.js 发送消息。
单击第一个组件时,它会发布一个帖子:
postal.publish({
channel: 'carts',
topic: 'item.add',
data: {
quantity: newQuantity
}
});
然后在第二个组件中,我在 componentDidMount() 中订阅了该频道:
postal.subscribe({
channel: 'carts',
topic: 'item.add',
callback: this.handleStorageChange.bind(this)
});
当我向订阅的组件添加窃听器时,它显示频道已成功订阅,但从未显示来自其他组件的帖子:
{"channel":"postal","topic":"subscription.created","data":{"event":"subscription.created","channel":"carts","topic":"item.add"},"timeStamp":"2018-03-14T01:59:38.309Z"}
当我向发布组件添加窃听时,它显示消息已发布:
{"channel":"carts","topic":"item.add","data":{"quantity":34},"timeStamp":"2018-03-14T01:59:41.844Z"}
我在这里做错了什么?