main.js:constsocket=newSockJS('http://192.168.1.107:8088/webSocketServer');Vue.prototype.$stompClient=Stomp.over(socket)index.vue:connect(){consttoken=this.$Cookies.get('token');this.$stompClient.connect({'token':token},(frame)=>{console.log('Connected:'+frame);this.$stompClient.subscribe('/user/queue/notifications',function(greeting){console.log(JSON.parse(greeting.body));});});},console:OpeningWebSocket...一直无法连接,但当我将服务器重启一次后就可以连接成功一次,然后就一直无法连接,必须将服务器重启而在index.vue中直接使用是没有任何问题的connect(){constsocket=newSockJS('http://192.168.1.107:8088/webSocketServer');this.stompClient=Stomp.over(socket);consttoken=this.$Cookies.get('token');this.stompClient.connect({'token':token},(frame)=>{console.log('Connected:'+frame);this.stompClient.subscribe('/user/queue/notifications',function(greeting){console.log(JSON.parse(greeting.body));});});},上下的区别仅仅是一个将Stomp注册到了原型上,一个是在页面方法内创建的,不明白为什么会一个错误,一个正常,注册到原型上之后只有重启服务器才能成功,之后所有的连接都是OpeningWebSocket...就连我换一个浏览器都不行
鸿蒙传说
繁花不似锦
相关分类