js事件消息
仓库地址
demo地址 常用api
eventbus.emit() eventbus.on() eventbus.off() eventbus.once()
如何使用
发送消息:可以多参数传递 import eventbus from './emitter' eventbus.emit('eventkey',"a") eventbus.emit('eventkey1',"a","b") eventbus.emit('eventkey2',"a","b","c") 监听消息 import eventbus from './emitter' eventbus.on('eventkey',(res)=>{}) eventbus.on('eventkey1',(res,res1)=>{}) eventbus.on('eventkey2',(res,res1,res2)=>{}) 监听一次 import eventbus from './emitter' eventbus.once('eventkey',(res)=>{}) 移除监听 import eventbus from './emitter' eventbus.off('eventkey')