Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

wx-event

dawangong9MIT1.0.7

小程序端事件总线,兄弟组件通信,子孙组件通信解决方案

readme

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.业务中使用 `javascript /* 事件监听 */ 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.