要点
- 全局websocket 连接
- 断线重连 (后台没有做心跳)
- 信息接收,跳转到对应页面
- 全局调用App.vue中的方法
websocket 处理
在App.vue中搭建连接
可参考uni-app示例中的websocket-global.vue
···
export default {
data() {
return {
connected: false,
connecting: false,
socketTask: false,
msg: false,
}
},
methods: {
connect() {
if (this.connected || this.connecting) {
/* uni.showModal({
content: '正在连接或者已经连接,请勿重复连接',
showCancel: false
}) */
return false
}
this.connecting = true
uni.showLoading({
title: '连接中...'
})
uni.connectSocket({
url: "你的链接地址+用户信息" + '?token=' + uni.