vue sockjsエラーThe connection has not been established yet
2395 ワード
参照先:https://blog.csdn.net/hzzhoushaoyu/article/details/49407835
import SockJS from "sockjs-client";
// websocket
stompClient: any = null;
// websocket
connection() {
const that = this;
//
let socket = new SockJS(`http://xxxx`, null, { timeout: 50000 });
// STOMP
that.stompClient = Stomp.over(socket);
that.stompClient.debug = (str: any) => {
// console.log(str + "
");
};
// websocket
that.stompClient.connect(
that.headers,
//
() => {
that.stompClient.subscribe("/xxxx", (msg: any) => {
//
if (msg.body) {
const res = JSON.parse(msg.body);
const items = res.data.datas.length > 0 ? res.data.datas : null;
if (items) {
// that.chart.appendData({
// seriesIndex: 0,
// data: items
// })
that.sourceData = that.sourceData.concat(items)
that.updateChart()
that.updateTime = moment(items[items.length - 1][0]).format('YYYY-MM-DD HH:mm:ss')
}
}
});
that.stompClient.subscribe("/user/queue/error", (msg: any) => {
//
console.log(" ", msg);
that.$notification.error({
message: ' ',
description: msg
});
});
},
//
(err: any) => {
//
console.log(" ", err);
// that.$notification.error({
// duration: 99,
// message: ' ',
// description: err
// });
// 1
setTimeout(() => {
that.stompClient = null;
that.resetHeader()
that.connection()
that.getSourceData()
}, 1000)
}
);
}
//
disconnect() {
this.resetHeader()
if (this.stompClient) {
this.stompClient.disconnect();
this.stompClient = null;
}
}
SockJS接続が確立されていないため、チャネルにデータを送信すると、エラーが発生します.The connection has not been established yet
WebSocketを使うとこの間違いを報告しますInvalidStateError: An attempt was made to use an object that is not, or is no longer, usable