【发布时间】:2017-04-08 17:06:19
【问题描述】:
我正在使用带有 Laravel Echo 的 Pusher 来为我的应用程序中的某些区域创建存在通道。 我所有的前端路由都是使用 Vue Router 完成的。
在路由之间切换时,Vue 路由器会根据我的路由设置加载某些组件。效果很好,但是,Pusher 不会自动断开用户与这些频道的连接。仅当我运行整页刷新时才会发生这种情况,这不是我想要的。
在我的组件中,加入 Pusher 频道的 js 代码在 mounted 内部,如下所示:
data() {
return {
users: [],
}
},
mounted() {
Echo.join('transaction.' + this.tid)
.here(users => {
this.users = users;
}
})
.joining(user => {
this.users.push(user);
})
.leaving(user => {
this.users.splice(this.users.indexOf(user), 1);
});
},
methods: {
// ...
},
如何在不刷新页面的情况下使用 Vue Router 路由断开用户与频道的连接?
谢谢。
【问题讨论】:
-
Echo.leave('transaction.' + this.tid);?
标签: javascript laravel vue.js pusher laravel-echo