【发布时间】:2019-09-30 06:38:25
【问题描述】:
我使用此代码首先加入在线状态频道,其次是 console.log 用户数。我得到了错误
未捕获的类型错误:无法读取未定义的属性“计数”
var presenceChannel = Echo.join('presenceChat');
presenceChannel.listen('EventEvent', (e) => {
console.log(e);
})
.here((users) => {
this.users = users;
console.log(this.users);
var count = presenceChannel.users.count;
var me = presenceChannel.users.me;
update_member_count(count);
console.log(count);
console.log(users)
})
我怀疑我没有按照我必须的方式使用 Pusher。
我在他登录时监听 EventEvent 并调度 $user。我做错了什么?或者我应该采取哪些步骤来计算 Pusher 的出席频道成员?让我感到困惑的是,在文档示例中没有事件监听器。那么如何使用 Pusher?
【问题讨论】:
-
就是说
presenceChannel.users是未定义的 -
@Roman Bobrik 我得到了包含有关用户加入数据的对象。我只是不明白为什么计数不是 1
-
做
console.log(presenceChannel),看看有没有users。也许您需要使用presenceChannel.members.count?例如:pusher.com/docs/channels/using_channels/… -
@Justinas 你为什么要回答?顺便谢谢你。我 console.log(presenceChannel) 并将用户更改为成员,这让我有机会继续我的工作。而且我也认为我不需要事件监听器。