“TypeError: Cannot read property ‘publish‘ of undefined“

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-21 11:22   22   0

解决办法:如果发布消息的组件中使用的代码形如this.PubSub.publish(‘xxx’, test),就将其中的this.去掉,即直接使用PubSub.publish(‘xxx’, test)。

在vue中进行组件间通信时,发现控制台出现如下异常:

[Vue warn]:Error in callback for watcher "xxx": "TypeError: Cannot read property 'publish' of undefined"

经过网上反复查询,未找到有用信息

将this.PubSub.publish(‘xxx’, xxx)中的this.去掉

居然成功了,究其原因,尚不明确。

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP