在react中配置socket.io.js

2019-10-25  本文已影响0人  小小潶

1.npm 安装soket.io.js

npm install socket.io-client  

2.封装socket.io.js

import io from 'socket.io-client';

import {socket_url} from '../../../components/config/config'

const socketBGP = io.connect('/bgp_events');

function tableDataSocket(cb){

  socketBGP.on('bgp_events', timestamp => {

    cb(null, timestamp)});

}

export {tableDataSocket};

3. tableDataSocket((err,timestamp)=>{

               console.log(timestamp)

      }

    })

上一篇 下一篇

猜你喜欢

热点阅读