【问题标题】:Get real time Pusherjs connection state via Laravel Echo in Nuxtjs通过 Nuxtjs 中的 Laravel Echo 获取实时 Pusherjs 连接状态
【发布时间】:2020-12-14 22:51:00
【问题描述】:

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

当我使用时:

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

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

【问题讨论】:

    标签: laravel-echo pusher-js nuxtjs


    【解决方案1】:

    我找到了解决办法:

    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-04-26
      • 2019-06-24
      • 2020-07-19
      • 2018-02-19
      • 1970-01-01
      • 2021-01-31
      • 2021-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多