webSocket实现方法
封装一个函数,开局调用就行
connectWS() {
var ws = null
ws = new WebSocket(
// "ws://192.168.199.187:9005/websocket/" 地址找后端
);
ws.onopen = function (evt) {
console.log("Connection open ...");
};
ws.onmessage = (e) => {
console.log('webSocket收到消息: ' + e.data) //数据处理可能有些复杂
},
ws.onclose = function (e) {
console.log('webSocket关闭: ')
}
ws.onerror = function (e) {
console.log('webSocket错误: ')
}