0

我想在 NuxtJs 页面中检查Pusherjsfrom的连接状态。$echo

当我使用:

mounted(){
   this.connection = this.$echo.connector.pusher.connection.state;
}

它可以工作,但它只设置初始连接状态,connecting它是静态的。

但是当我使用:

computed:{
   connection: this.$echo.connector.pusher.connection.state
}

它返回错误:

TypeError
Cannot read property '$echo' of undefined

那么如何实时通知连接状态呢?

4

1 回答 1

0

我找到了解决方案:

this.$echo.connector.pusher.connection.bind("state_change", (states) => {
   // states = {previous: 'oldState', current: 'newState'}
});

参考: https ://pusher.com/docs/channels/using_channels/connection#binding-to-all-state-changes

于 2020-08-26T12:24:31.080 回答