vue 轴实现SockJS +websocket请求

1Vue里引入  import websocket from '../../utils/websocket.js';**PS:但是好像没有引入进来不知道为什么,确定路径没有写错**
2// 安装并引入相关模块——此部分写在了websocket.js里
import SockJS from 'sockjs-client';
import Stomp from 'stompjs';
export default {
 data() {
  return {
  dataList: []
  };
 },
 mounted:function(){
   console.log("09999")
  this.initWebSocket();
 },
 beforeDestroy: function () {
  // 页面离开时断开连接,清除定时器
  this.disconnect();
  clearInterval(this.timer);
 },
 methods: {
  initWebSocket() {
  this.connection();
  let self = this;
  // 断开重连机制,尝试发送消息,捕获异常发生时重连
  this.timer = setInterval(() => {
   try {
   self.stompClient.send("test");
   } catch (err) {
   console.log("断线了: " + err);
   self.connection();
   }
  }, 5000);
  },
  removeTab(targetName) {
  console.log(targetName)
  },
  connection() {
  // 建立连接对象
  this.socket = new SockJS('ws://47.94.52.215:8001/WS/');//连接服务端提供的通信接口
  // 获取STOMP子协议的客户端对象
  this.stompClient = Stomp.over(this.socket);
  // 定义客户端的认证信息,按需求配置
  var headers = {
   login: 'mylogin',
   passcode: 'mypasscode',
   // additional header
   'client-id': 'my-client-id'
  };
  // 向服务器发起websocket连接
  this.stompClient.connect(headers,(frame) => {
    console.log("发起websocket连接成功");
    // this.stompClient.subscribe('/pc', (res) => { // 订阅服务端提供的某个topic
    // consolel.log(res.body); // msg.body存放的是服务端发送给我们的信息
    // });
     this.stompClient.subscribe('/topic/chat_msg', (msg) => { // 订阅服务端提供的某个topic
     consolel.log(msg.body); // msg.body存放的是服务端发送给我们的信息
     });
  }, (err) => {
    console.log("发起websocket连接失败");
  });

  },
  disconnect() {
  if (this.stompClient != null) {
   this.stompClient.disconnect();
   console.log("Disconnected");
  }
  }
 }
};

1