我在onShow生命周期里去向后端发送消息,这时切换到其它页面后回来不会执行socketTask.onOpen里的代码 为什么
onShow: function() {
console.log(wx.getStorageSync('phone'));
//获取当前经纬度
this.getLocation();
//获取设备状态
this.getActive();
console.log(socketTask);
if(!socketTask && wx.getStorageSync('isLogin')){
this.connectWebsocket();
}else{
if (wx.getStorageSync('isLogin')) {
socketTask.onMessage((res) => {
console.log(res);
console.log('socketMsg:' + res.data)
const result = res.data;
if (result === 'Charging') {
this.setData({
userStatus: result
})
}
})
socketTask.onOpen(() => {
console.log('socket向后端发送数据')
const phone = wx.getStorageSync('phone') || app.globalData.phone;
console.log('phone' + phone)
socketTask.send({
data:String(phone)
})
})
}
}
},
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)