Commit f859370e authored by 沈翠玲's avatar 沈翠玲

websocket修改

parent cd5986e5
...@@ -11,10 +11,12 @@ const useSocketStore = defineStore('socket', { ...@@ -11,10 +11,12 @@ const useSocketStore = defineStore('socket', {
timerHeart: undefined, timerHeart: undefined,
timerServerHeart: undefined, timerServerHeart: undefined,
handClose: false, handClose: false,
url: '',
msg: '', msg: '',
}), }),
actions: { actions: {
connection(url, token) { connection(url, token) {
this.url = url
if ('WebSocket' in window) { if ('WebSocket' in window) {
this.createWebSocket(url, token); this.createWebSocket(url, token);
} else { } else {
...@@ -93,7 +95,7 @@ const useSocketStore = defineStore('socket', { ...@@ -93,7 +95,7 @@ const useSocketStore = defineStore('socket', {
//没连上会一直重连, 设置迟延,避免请求过多 //没连上会一直重连, 设置迟延,避免请求过多
this.timerReconnect = setTimeout(() => { this.timerReconnect = setTimeout(() => {
//setTimeout 到点了执行 //setTimeout 到点了执行
this.connection(); this.connection(this.url);
this.lockReconnect = false; this.lockReconnect = false;
}, 5000); }, 5000);
}, },
...@@ -135,7 +137,6 @@ const useSocketStore = defineStore('socket', { ...@@ -135,7 +137,6 @@ const useSocketStore = defineStore('socket', {
console.log('手动关闭ws'); console.log('手动关闭ws');
this.handClose = true; this.handClose = true;
this.clearTimer(); this.clearTimer();
console.log('ws', this.ws);
if (this.ws && this.ws.close) { if (this.ws && this.ws.close) {
this.ws.close(); this.ws.close();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment