websocket 钩子

This commit is contained in:
a0049873 2022-07-26 14:05:58 +08:00
parent 20e75d78cc
commit 486c3e8d46
1 changed files with 12 additions and 3 deletions

View File

@ -2,7 +2,7 @@
* @Author: hisense.wuhongjian
* @Date: 2022-05-06 11:12:00
* @LastEditors: hisense.liangjunhua
* @LastEditTime: 2022-07-21 17:09:10
* @LastEditTime: 2022-07-26 11:27:50
* @Description: 告诉大家这是什么
-->
<template>
@ -31,19 +31,28 @@
const locale = zhCN
const token = Cookies.get('ucsToken')
console.log('token=================>', token)
var ws = new WebSocket(
let ws = new WebSocket(
`ws://${window.SITE_CONFIG['websocketURL']}/websocket?token=${token}`
)
// ws.send()
// onmessage
ws.onmessage = function (e) {
console.log('服务器返回的信息: ' + e.data)
console.log('WebSocket服务器返回的信息: ' + e.data)
mybus.emit('getMynotice')
//
if (router.currentRoute.value.name === 'mynoticeView') {
mybus.emit('noticeListInit')
}
}
ws.onerror = function (e) {
console.log('WebSocket连接异常============================>', e)
ws = new WebSocket(
`ws://${window.SITE_CONFIG['websocketURL']}/websocket?token=${token}`
)
}
ws.onclose = function (e) {
console.log('WebSocket连接断开============================>', e)
}
onBeforeUnmount(() => {
// 4.,
ws.close()