From 6a3547dad2174d8a86fe42e7c65780f0ce3b4148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Mon, 7 Mar 2022 12:27:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EsignalR=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=87=8D=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Vue/src/utils/signalR.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ZR.Vue/src/utils/signalR.js b/ZR.Vue/src/utils/signalR.js index 13631e9..0a94210 100644 --- a/ZR.Vue/src/utils/signalR.js +++ b/ZR.Vue/src/utils/signalR.js @@ -13,16 +13,19 @@ export default { init(url) { const connection = new signalR.HubConnectionBuilder() .withUrl(url, { accessTokenFactory: () => getToken() }) + .withAutomaticReconnect()//自动重新连接 .build(); this.SR = connection; // 断线重连 connection.onclose(async () => { console.log('断开连接了') + console.assert(connection.state === signalR.HubConnectionState.Disconnected); + // 建议用户重新刷新浏览器 await this.start(); }) connection.onreconnected(() => { - console.log('断线重连') + console.log('断线重新连接成功') }) this.receiveMsg(connection); // 启动