socket io

1 npm install "socket.io-client": "^2.2.0",

2 import io from 'socket.io-client'; // 引入socket.io-client

3 initSocket() {
const socket = io(window.config.socketapi); // 路径
this.socket = socket;
},

4 socketEmit(key, value) {
this.socket.emit(key, value);
},

5 socketOn(key) {
  this.socket.on(key, data => {
      data = > socket返回值
  });
},

你可能感兴趣的:(socket io)