initWebSocket(){
const wsuri = 'ws://xxxxxxxxxxx';
this.websock = new WebSocket(wsuri);
this.websock.onopen = this.websocketonopen;
this.websock.onerror = this.websocketonerror;
this.websock.onmessage = this.websocketonmessage;
this.websock.onclose = this.websocketclose;
this.$store.state.websock = this.websock
},
websocketonopen() {
console.log("WebSocket连接成功");
this.btnxx()
},
websocketonerror(e) {
console.log("WebSocket连接发生错误");
},
websocketonmessage(e){
const redata = JSON.parse(e.data);
},
websocketsend(agentData){
this.websock.send(agentData);
},
websocketclose(e){
console.log("socket已经关闭")
},
created(){
this.initWebSocket()
},
btnxx(){
let a = {}
a.type = xxxxxxxxxxxxxxxx
a.content = JSON.stringify(xxxxxxxxxxxx)
let b = JSON.stringify(a)
this.websocketsend(b)
},