socket地址配置

  1. // 根目录/config/index.js
  2. const LIVESOCKET = "wss://配置您的wss地址"

socket说明

  1. /**
  2. 根目录/utils/websocket.js
  3. 该websocket类基于uni的websocket,支持websocket链接、断开、断线重连、心跳检测和发送消息
  4. **/
  5. // 链接websocket
  6. import wsRequest from '@/utils/websocket.js'
  7. let websocket = new wsRequest(6000)
  8. Vue.prototype.$socket = websocket // 将socket实例绑定至全局vue原型链上
  9. // 断线重连
  10. this.$socket.manualReconnect()
  11. // 关闭链接
  12. this.$socket.colse()
  13. // 发送消息
  14. this.$socket.send(JSON.stringify({
  15. type: 'readmsg',
  16. data: {
  17. }
  18. }))