目录
在页面的js文件中引入
import {
createStoreBindings
} from 'mobx-miniprogram-bindings'
import {
store
} from '../../store/store'
在 onLoad: function ()里写
this.storeBindings = createStoreBindings(this, {
store,
fields: ['numA', 'numB', 'sum'],
actions: ['updateNum1']
})
在 onUnload: function ()里写
onUnload: function () {
this.storeBindings.destroyStoreBindings()
},
在wxml里写
<view>{{numA}} + {{numB}} = {{sum}}</view>
<van-button type="primary" bindtap="btnHandler1" data-step="{{1}}">numA + 1</van-button>
<van-button type="danger" bindtap="btnHandler1" data-step="{{-1}}">numA - 1</van-button>
事件绑定
btnHandler1(e) {
this.updateNum1(e.currentTarget.dataset.step)
}