引用 websocket vue 初始化事件触发
作者:互联网
//初始化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();
}
标签:初始化,websocketMessage,vue,websocket,log,示例,send,console 来源: https://www.cnblogs.com/yu-heng-xing/p/16409183.html