From 2dc5782b947ed7f9393e7b5ecfe158376056e54e Mon Sep 17 00:00:00 2001 From: z_yu <1534695664@qq.com> Date: Mon, 15 Aug 2022 11:24:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=A8=E7=A6=81=E4=BF=A1=E6=81=AF=E4=B9=9F?= =?UTF-8?q?=E4=B8=8D=E7=94=A8websocket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/components/SecurityDoor.vue | 41 +-------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/src/views/components/SecurityDoor.vue b/src/views/components/SecurityDoor.vue index a41e4e2..142aeef 100644 --- a/src/views/components/SecurityDoor.vue +++ b/src/views/components/SecurityDoor.vue @@ -38,8 +38,7 @@ export default { }, data() { return { - tableData: [], // 正在展示的数据 - socket: null + tableData: [] // 正在展示的数据 } }, created() { @@ -48,12 +47,8 @@ export default { this.tableData.push(...data) } }) - this.openSocket() }, destroyed() { - if (this.socket) { - this.socket.close() - } }, methods: { // 表格隔行变色 @@ -63,40 +58,6 @@ export default { } else { return '' } - }, - openSocket() { - if (!('WebSocket' in window)) { - console.log('您的浏览器不支持WebSocket') - } else { - console.log('您的浏览器支持WebSocket') - const socketUrl = process.env.VUE_APP_WS_API + '/webSocket' - if (this.socket != null) { - this.socket.close() - this.socket = null - } - this.socket = new WebSocket(socketUrl) - // 打开事件 - this.socket.onopen = () => { - console.log('websocket已经打开') - // 心跳检测重置 - // this.heartCheck.start() - } - // 获得消息 - this.socket.onmessage = (msg) => { - console.log(msg) - // this.tableData.push(JSON.parse(msg.data.slice(7, msg.data.length - 2)).Data) - this.tableData.push(JSON.parse(msg.data.slice(7, msg.data.length - 2)).Data) - } - // 关闭事件 - this.socket.onclose = function() { - console.log('websocket已关闭') - } - // 发生了错误事件 - this.socket.onerror = function(e) { - console.log('websocket发生了错误') - console.log(e) - } - } } } }