<template></template>
<script>
export default {
created () {
this.initWebSocket()
},
methods: {
initWebSocket: function () {
let host = window.location.hostname
const url = `ws://${host}:9010/xxxxxx/websocket/123`
this.websock = new WebSocket(url)
this.websock.onopen = this.websocketonopen
this.websock.onerror = this.websocketonerror
this.websock.onmessage = this.websocketonmessage
},
websocketonopen: function () { },
websocketonerror: function (e) {
this.$message.error('网络连接失败!')
},
websocketonmessage: function ({ data }) {
},
websocketclose: function (e) { }
}
}
</script>
|