main.js:
const socket = new SockJS("http://192.168.1.107:8088/webSocketServer");
Vue.prototype.$stompClient = Stomp.over(socket)
index.vue:
connect() {
const token = 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:
Opening Web Socket...
has been unable to connect, but when I restart the server once, I can connect successfully once, and then I have been unable to connect, so I have to restart the server
but using it directly in index.vue is no problem
. connect() {
const socket = new SockJS("http://192.168.1.107:8088/webSocketServer");
this.stompClient = Stomp.over(socket);
const token = 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));
});
});
},
The difference between the top and bottom of is that one registers Stomp on the prototype, one is created in the page method, and I don"t understand why there is an error, a normal,
.after registering on the prototype, you can only succeed by restarting the server. After that, all connections are Opening Web Socket..
I can"t even change my browser