websocket使用:
跳转路由前,一定要销毁链接。
mounted () {
this.connectWebSocket()
},
connectWebSocket () { // websocket推送
const baseUrl = window.config.baseUrl
const viborderStompWebsocket = ${window.config.projectName}${window.config.viborderStompWebsocket}
let socket = new SockJS(
baseUrl + viborderStompWebsocket
)
this.socketInfo.client = Stomp.over(socket)
let path = /topic/commandTopic_${this.socketInfo.site}
let scb = (msg) => { // 针对订阅路径处理推送逻辑
// console.log(‘放行确认站-------------------’, msg)
if (msg.command === ‘vehicleRefresh’) {
// this.listQuery()
}
}
connect({client: this.socketInfo.client, path, scb, header: this.socketInfo.header, reconCallBack: this.connectWebSocket})
},
beforeDestroy () {
this.socketInfo.client && disconnect({client: this.socketInfo.client}) // socket断开连接
},