openSocket() {
      let url = `ws://172.xx.10.xxx/tdssamsWs/webSocket/${this.uuid}`;
      //  url=url.replace("https","ws").replace("http","ws");
      let socket = new WebSocket(url);
      //打开事件
      socket.onopen = function () {
        console.log("websocket已打开");
        //socket.send("这是来自客户端的消息" + location.href + new Date());
      };
      //获得消息事件
      socket.onmessage = function (msg) {
        console.log(msg, 666693);
        console.log(msg.data);
        //发现消息进入    开始处理前端触发逻辑
      };
      //关闭事件
      socket.onclose = function () {
        console.log("websocket已关闭");
      };
      //发生了错误事件
      socket.onerror = function () {
        console.log("websocket发生了错误");
      };
    },
Logo

前往低代码交流专区

更多推荐