1.0.7 • Published 4 years ago

wx-event v1.0.7

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

wx-event release MIT

小程序端事件总线,兄弟组件通信,隔代组件通信解决方案。

DOC

使用支持

  • CommonJS
  • ES6 module
import Event from 'wx-event';
const { Event } = require('wx-event');

How to use ?

npm i wx-event

1.创建调度中心(例如:event-manage.js)

import Event from 'wx-event';
/* 注册事件 */
wx.event.$increase(new Event('update')); 

2.将调度中心引入到app.js中

import './utils/event-manage';

3.业务中使用

/* 事件监听 */
wx.event.$on('update', params => {
      this.setData(params)
    });

/ 事件广播 / wx.event.$broadcast('update', params);

4.其他api支持
- $off: 关闭监听
```javascript
wx.event.$off('update');
  • $once: 一次性监听
wx.event.$once('update', params => {
      this.setData(params)
    });
  • $remove: 移除指定事件所有监听
wx.event.$remove('update');
  • $clear: 清空所有事件所有监听
wx.event.$clear()

tips: 为了保证this的指向正确,请使用箭头函数。如何支持ES6?

License

wx-event is MIT licensed.

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago