1.0.5 • Published 5 years ago

weapp-event v1.0.5

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

weapp-event

安装

npm i weapp-event -S

使用

实例初始化

把实例挂载在 App 中,方便每个 Page 去调用

// app.js
import Event from 'weapp-event'
App({
    event: Event,
    ...
})

监听事件

//page.js
var app = getApp()
Page({
    onLoad: function(){
        app.event.on('do-foo', this, this.doFoo)
    },
    doFoo: function(id) {
        ...
    },
    ...
})

触发事件

//order_detail.js
var app = getApp()
Page({
    doSomething: function() {
        ... 
        app.event.emit('do-foo', 123)
    },
    ...
})

注销事件

var app = getApp()

Page({
    onUnload: function(){
        // remove all
        app.event.off()
        // remove all callbacks
        app.event.off('do-foo')
        // remove specific callbacks
        app.event.off('do-foo', this)
    },
    ...
})
1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago