wx-event-handler

WxEventHandler used in wechat minipargram, help you handle your event simply, just like you use Vue

Usage no npm install needed!

<script type="module">
  import wxEventHandler from 'https://cdn.skypack.dev/wx-event-handler';
</script>

README

WxEventHandler

Make you feel like use Vue's event controler, just support in single page init your single instance.

example code

demo

  const WxEventHandler = require('wx-event-handler').default;

  //实例化一个事件控制器
  const myEventHandler = new WxEventHandler("MyPageName");

  Page({
    sayHello(hello, name){
      wx.showModal({
        title: hello,
        content:name
      });
    },
    onLoad(){
      //监听
      myEventHandler.on("sayHelloTo", this.sayHelloTo);
    },
    onUnload(){
      //取消监听
      myEventHandler.off("sayHelloTo");
    },
    onClick(){
      //发射事件
      myEventHandler.emit("sayHelloTo", "Hello", "Peter Yuan");
    }
  }