消息中心添加 websocket
This commit is contained in:
parent
66e479ed5f
commit
10f3323676
|
@ -122,6 +122,7 @@
|
||||||
import { mynotice } from '@/api/home'
|
import { mynotice } from '@/api/home'
|
||||||
import { useStore } from 'vuex'
|
import { useStore } from 'vuex'
|
||||||
import { getSgcTotal } from '@/api/home'
|
import { getSgcTotal } from '@/api/home'
|
||||||
|
import Cookies from 'js-cookie'
|
||||||
import mybus from '@/myplugins/mybus'
|
import mybus from '@/myplugins/mybus'
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
@ -284,6 +285,18 @@
|
||||||
// getMynotice()
|
// 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(() => {
|
onMounted(() => {
|
||||||
getSgcTotal().then((res) => {
|
getSgcTotal().then((res) => {
|
||||||
// console.log('初始化========================>', res.data.data.count)
|
// console.log('初始化========================>', res.data.data.count)
|
||||||
|
@ -322,6 +335,8 @@
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
mybus.off('getSgcNum')
|
mybus.off('getSgcNum')
|
||||||
mybus.off('getMynotice')
|
mybus.off('getMynotice')
|
||||||
|
// 4.卸载前, 关闭链接
|
||||||
|
ws.close()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
|
Loading…
Reference in New Issue