vue中使用Sockjs和stompjs实现实时数据
引入import SockJS from'sockjs-client';importStomp from 'stompjs';代码let socket = new SockJS('api/gcIot-supervise-manholecover/webSocketEndPoint');// 路径this.stompClient = Stomp.over(s...
·
引入
import SockJS from 'sockjs-client';
import Stomp from 'stompjs';
代码
let socket = new SockJS('api/gcIot-supervise-manholecover/webSocketEndPoint'); // 路径
this.stompClient = Stomp.over(socket);
let headers = {
Authorization:getToken() // 获取token
}
this.stompClient.connect(headers, (frame) => { // 连接
console.log(frame);
this.stompClient.subscribe('/topic/greetings', (greeting) => { // 这里接受后端推送的数据
console.log(greeting)
},headers);
this.stompClient.send("/app/demo", headers,'134567'); // 发送数据 1234567
},(err) => {
console.log('失败')
console.log(err)
})
更多推荐
已为社区贡献4条内容
所有评论(0)