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