websocket代码提交

This commit is contained in:
2025-01-17 09:14:19 +08:00
parent 07a5e32579
commit 9e8ed310fc
3 changed files with 19 additions and 12 deletions

View File

@@ -25,17 +25,18 @@ export default class SocketService {
reconnectDelay= 5000; // 重新连接延迟,单位毫秒
// 定义连接服务器的方法
connect(url) {
connect() {
// 连接服务器
if (!window.WebSocket) {
return console.log('您的浏览器不支持WebSocket');
}
console.log(url)
// let token = $.cookie('123');
// let token = '4E6EF539AAF119D82AC4C2BC84FBA21F';
const url = 'ws://192.168.1.133:7777/hello?name=cdf'
this.ws = new WebSocket(url);
// 连接成功的事件
this.ws.onopen = () => {
@@ -60,6 +61,13 @@ export default class SocketService {
};
this.ws.onerror = () => {
ElMessage.error("webSocket连接异常");
};
// 得到服务端发送过来的数据
this.ws.onmessage = (event) => {
let message: { [key: string]: any };