vue中 搭配 springboot整合websocket实现一对一消息推送和广播消息推送

https://www.cnblogs.com/javafirst0/p/11208563.html

https://www.cnblogs.com/luoxuemei/p/10115679.html

https://www.cnblogs.com/luoxuemei/p/10115679.html

 

 

mounted(){
    this.connect(this);
  },

methods: {
connect(_this) {
      var socket = new SockJS(window.g_api.BASE_API+'/readerSocket'); //1连接SockJS的endpoint是“endpointWisely”,与后台代码中注册的endpoint要一样。
      let stompClient = Stomp.over(socket);//2创建STOMP协议的webSocket客户端。
      stompClient.connect({}, function(frame) {//3连接webSocket的服务端。
          // setConnected(true);
          console.log('开始进行连接Connected: ' + frame);
          //4通过stompClient.subscribe()订阅服务器的目标是'/topic/getResponse'发送过来的地址,与@SendTo中的地址对应。
          stompClient.subscribe('/topic/getNotics', function(respnose){
            console.log(respnose)
            console.log(respnose.body)
            console.log(_this)
            if(respnose.body=='密码重置'){
              _this.resetPassStatus = true;
              _this.$store.commit("FORGET_PASS_STATUS",true);
            }
              // showResponse(JSON.parse(respnose.body).responseMessage);
          });
      });
     
    },
}

 

posted @ 2021-07-26 14:31  遇你温柔如初  阅读(688)  评论(0编辑  收藏  举报