worker-bus
v1.0.5
Published
Dashboard data load by socket through web-worker
Downloads
2
Maintainers
Readme
使用说明 Usage
引入 Import
//main.js
import WorkerBus from "worker-bus";
Vue.use(WorkerBus);
Vue中使用$wb
<!-- worker.js -->
$wb.one('./worker.js')
<!-- config Loop valid -->
$wb.configValid((loopID, data) => loopID == data.loopID)
<!-- 获取socket状态 -->
this.$wb.on('__socket__status', (payload) => {
this.socket_status = payload.data.status
})
<!-- 获取socket回调队列 -->
this.$wb.on('__socket__queue', (payload) => {
this.socket_queue = payload.data.queue
})
<!-- 注册定时任务 -->
this.$wb.register([
{ loopID: 1, data: { payload: { from: 'localhost', target: 'demo:200ms', id: '10001' }, timeout: 60, loop: true } }
])
<!-- 监听数据返回 60ms 返回一次-->
this.$wb.on(1, msg => {
console.log(msg.count)
})
DEMO
//启动静态服务器 http://localhost:8080
npm run dev
// 启动websocket服务器 ws://localhost:3000/basic
npm run server:dev