websocket首次连接后 第二次socketTask.onOpen为什么不会触发?
我在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) }) }) } } },