消息中心添加 websocket
This commit is contained in:
parent
66e479ed5f
commit
10f3323676
|
@ -122,6 +122,7 @@
|
|||
import { mynotice } from '@/api/home'
|
||||
import { useStore } from 'vuex'
|
||||
import { getSgcTotal } from '@/api/home'
|
||||
import Cookies from 'js-cookie'
|
||||
import mybus from '@/myplugins/mybus'
|
||||
const store = useStore()
|
||||
const router = useRouter()
|
||||
|
@ -284,6 +285,18 @@
|
|||
// getMynotice()
|
||||
// })
|
||||
// }
|
||||
// 建立链接 -- 携带cookie参数
|
||||
const token = Cookies.get('ucsToken')
|
||||
console.log('token=================>', token)
|
||||
var ws = new WebSocket(
|
||||
`ws://15.2.21.238:8888/renren-admin/websocket?token=${token}`
|
||||
)
|
||||
// ws.send()给服务器发送信息
|
||||
// 服务器每次返回信息都会执行一次onmessage方法
|
||||
ws.onmessage = function (e) {
|
||||
// console.log('服务器返回的信息: ' + e.data)
|
||||
getMynotice()
|
||||
}
|
||||
onMounted(() => {
|
||||
getSgcTotal().then((res) => {
|
||||
// console.log('初始化========================>', res.data.data.count)
|
||||
|
@ -322,6 +335,8 @@
|
|||
onBeforeUnmount(() => {
|
||||
mybus.off('getSgcNum')
|
||||
mybus.off('getMynotice')
|
||||
// 4.卸载前, 关闭链接
|
||||
ws.close()
|
||||
})
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
|
|
Loading…
Reference in New Issue