美文网首页
在react中配置socket.io.js

在react中配置socket.io.js

作者: 小小潶 | 来源:发表于2019-10-25 14:01 被阅读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)

      }

    })

相关文章

网友评论

      本文标题:在react中配置socket.io.js

      本文链接:https://www.haomeiwen.com/subject/nndsvctx.html