小程序
全局数据共享
import {createStoreBindings} from 'mobx-miniprogram-bindings'
import {store} from '../../store/store'
onLoad: function (options) {
// 调用createStoreBindings方法
this.storeBindings= createStoreBindings(this,{
store,//数据源
fields:['numA','numB','sum'],//用到哪些字段
actions:['updateNum1']
})
},
onUnload: function () {
this.storeBindings.detroyStoreBindings()
},
在页面中使用store成员
xml
点击查看代码
<van-button type="primary"
bindtap="add" data-step="{{1}}">numA+1</van-button>
<van-button type="danger" bindtap="add" data-step="{{-1}}"> numA-1</van-button>
点击查看代码
add(e){
this.updateNum1(e.target.dataset.step)
},
posted on 2022-05-02 21:37 努力inginging 阅读(89) 评论(0) 编辑 收藏 举报