引入

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)
      })
Logo

前往低代码交流专区

更多推荐