websocket使用方法
initWebSocket() {
let uriS = 'ws://130.10.7.92:1234/websocket/';
this.socket = new WebSocket(uriS);
this.socket.onopen = this.open;
this.socket.onerror = this.error;
this.socket.onmessage = this.getMessage;
this.socket.onclose = this.close;
},
open: function () {
console.log('socket连接成功');
},
error: function () {
console.log('socket连接错误');
},
getMessage: function (msg) {
console.log(msg)
if (JSON.parse(msg.data) != '0') {
} else {
}
},
send: function () {
this.socket.send(params);
},
close: function () {
console.log("socket已经关闭")
},