消息中心添加 websocket

This commit is contained in:
a0049873 2022-07-21 14:34:09 +08:00
parent 66e479ed5f
commit 10f3323676
1 changed files with 15 additions and 0 deletions

View File

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