< script >
export default {
name:"- sharpindex2",
methods: {
submit: function() {
this.websocketsend({a:1})
},
threadPoxi: function() { //
//
const agentData = "mymessage";
//ws
if (this.websock.readyState === this.websock.OPEN) {
this.websocketsend(agentData)
}
// 300
else if (this.websock.readyState === this.websock.CONNECTING) {
let that = this; //this
setTimeout(function() {
that.websocketsend(agentData)
}, 300);
}
// 500
else {
this.initWebSocket();
let that = this; //this
setTimeout(function() {
that.websocketsend(agentData)
}, 500);
}
},
initWebSocket: function() { //weosocket
const wsuri = "ws://192.168.1.186:9353/websocket";
this.websock = new WebSocket(wsuri);
this.websock.onmessage = this.websocketonmessage;
this.websock.onclose = this.websocketclose;
},
websocketonmessage: function(e) { //
const redata = JSON.parse(e.data);
console.log("onmessage=" + redata);
},
websocketsend(agentData) { //
this.websock.send(agentData, function(data) { console.log(data) });
},
websocketclose: function(e) { //
console.log("connection closed (" + e.code + ")");
},
loginBuy: function() {},
loginSell: function() {}
},
created () {
this.initWebSocket()
}
}
< / script >