Browse Source

门禁信息也不用websocket

master
z_yu 3 years ago
parent
commit
2dc5782b94
  1. 41
      src/views/components/SecurityDoor.vue

41
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)
}
}
}
}
}

Loading…
Cancel
Save