【微信小程序】Mobx--绑定多个 store 以及命名空间

在实际开发中,一个页面或者组件可能会绑定多个 Store ,这时候我们可以将 storeBindings 改造成数组。数组每一项就是一个个要绑定的 Store

如果多个 Store 中存在相同的数据,显示会出现异常。还可以通过 namespace 属性给当前 Store 开启命名空间,在开启命名空间以后,访问数据的时候,需要加上 namespace 的名字才可以

javascript 复制代码
// behavior.js

import { BehaviorWithStore } from 'mobx-miniprogram-bindings'
import { numStore } from '../../stores/numstore'

export const indexBehavior = BehaviorWithStore({
  storeBindings: [
    {
      namespace: 'numStore',
      store: numStore,
      fields: ['numA', 'numB', 'sum'],
      actions: ['update'],
    }
  ]
})
javascript 复制代码
// index/index.wxml
<view>{{ numStore.numA }} + {{ numStore.numB }} = {{numStore.sum}}</view>

摘录:https://blog.csdn.net/qq_63358859/article/details/136347834

相关推荐
肖有米XTKF86461 天前
肖有米团队开发:青蓝山泉送水模式系统
小程序·团队开发·零售·csdn开发云
double_eggm1 天前
微信小程序7
微信小程序·小程序
程序鉴定师1 天前
上海小程序开发的坚实保障与行业优势解析
大数据·小程序
double_eggm2 天前
微信小程序8
微信小程序·小程序
MageGojo2 天前
小程序每日一谜怎么做:riddle 接口接入示例
windows·小程序·apache·谜语
kyh10033811202 天前
Cocos Creator 《打螺丝消除游戏》源码+实现
游戏·微信小程序·小程序·打螺丝小游戏源码·微笑小游戏源码
烂不烂问厨房3 天前
支付宝小程序camera录制视频并上传注意事项
小程序·音视频
PeanutSplsh3 天前
wx.setStorage 存的数据,没你以为的那么安全
微信小程序
我是伪码农3 天前
小程序125-150
小程序
帅次3 天前
讯飞与腾讯云:Android 实时语音识别服务对比选择
android·ios·微信小程序·小程序·android studio·android runtime