1. 程式人生 > 其它 >vue中 搭配 springboot整合websocket實現一對一訊息推送和廣播訊息推送

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); }); }); }, }