作者:看吧看吧说你你不信 | 来源:互联网 | 2023-05-26 11:58
初始化websocketinitWebsocket(wbUrl){this.websocketnewWebSocket(wbUrl);this.websocket.onopenth
//初始化websocket
initWebsocket(wbUrl){
this.websocket = new WebSocket(wbUrl);
this.websocket.Onopen= this.websocketOpen;
this.websocket.Onmessage= this.websocketMessage;
this.websocket.Onerror= this.websocketError;
},
//发送请求
websocketOpen(){
console.log('websocketOK');
this.websocket.send("自己的传值内容");
},
//websocket链接成功
websocketMessage(e){
console.log(e)
},
//建立
created(){
this.initWebsocket('你的websocketUrl'); 示例一
this.websocket.send("{ 'mark': '6' }"); 示例二
},
//销毁
destroyed(){
this.websocket.close();
}