12345678910111213141516171819202122232425262728293031323334353637 |
- import store from '@/store'
- let ws = null
- export function wsSocket () {
- ws = new WebSocket(`${PLATFROM_CONFIG.socketUrl}`)
- ws.onopen = function () {
- console.log('ws打开')
- }
- ws.onmessage = function (res) {
- const datas = JSON.parse(res.data)
- store.dispatch('app/getWsData', datas)
- console.log('ws数据', datas)
- }
- ws.onerror = function (err) {
- console.log('ws错误', err)
- }
- ws.onclose = function () {
- console.log('ws关闭')
- }
- }
- export function wsSendData (msg) {
- if (ws) {
- ws.send(msg)
- }
- }
- export function wsSocketClose () {
- if (ws) {
- ws.close()
- }
- }
|