socket: function() {
let _this = this;
//创建websocket对象
this.socketTask = uni.connectSocket({
url: this.url1,
success(data) {
console.log("websocket连接成功");
},
});
// 消息的发送和接收必须在正常连接打开中,才能发送或接收【否则会失败】
this.socketTask.onOpen((res) => {
// 注:只有连接正常打开中 ,才能正常成功发送消息
})
// 注:只有连接正常打开中 ,才能正常收到消息
this.socketTask.onMessage((res) => {
let msg = res.data;
console.log(msg);
_this.navList[0].orderList[0].content.push(JSON.parse(msg))
_this.hei()
})
// 这里仅是事件监听【如果socket关闭了会执行】
this.socketTask.onClose(() => {
console.log("已经被关闭了")
})