您当前的位置: 首页 > 

彭世瑜

暂无认证

  • 3浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

mitt.js:小型事件发布订阅库

彭世瑜 发布时间:2022-07-24 16:46:15 ,浏览量:3

Tiny 200b functional event emitter / pubsub.

文档

  • github: https://github.com/developit/mitt
  • https://www.npmjs.com/package/mitt

安装

npm install --save mitt

cdn


使用示例

import mitt from 'mitt'

const emitter = mitt()

function onFoo(data) {
    console.log(data);
}

const TOPIC = 'topic'

// 订阅
emitter.on(TOPIC, onFoo)   

// 发布事件
emitter.emit(TOPIC, { a: 'b' })

// 取消订阅
emitter.off(TOPIC, onFoo)
关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0540s