import io from '@hyoga/uni-socket.io'; class socket { constructor() { this.socket = null; this.init(); } init () { this.socket = io('http://192.168.31.101:3000', { query: {}, transports: [ 'websocket', 'polling' ], timeout: 5000, }); this.onEvent(); } onEvent() { this.socket.on("connect", () => { console.log("链接建立成功...") uni.showToast({ icon: "none", title: "debug 成功链接服务器...", duration: 1000, }); }); this.socket.on("error", (msg) => { console.log('链接错误:', msg); }) } } export default new socket();