【微信小程序】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

相关推荐
2601_9499506316 小时前
考研英语资料太散?用小程序把真题、词汇和错题放到一起
人工智能·学习·考研·小程序·刷题·小程序推荐
lhldsg19 小时前
树洞倾诉的核心需求与产品定位误区
java·前端·小程序
lhldsg19 小时前
宠物同城领养平台开发实战:从需求分析到上线部署指南
java·前端·小程序·需求分析·宠物
171320330计算机毕设编程20 小时前
基于SpringBoot的在线拍卖系统
android·java·spring boot·小程序·课程设计
2501_9160074721 小时前
Flutter与游戏App加固避坑指南:如何为混合开发与高交互应用选对安全方案?
安全·flutter·游戏·ios·小程序·uni-app·iphone
andrsted1 天前
老师可以用小程序在线整理题库、课堂检测和错题集
学习·微信小程序·小程序·学习方法
show4331 天前
2026小程序视频转文字多语种识别引擎选型:22方言25外语
小程序·音视频
学习星球2 天前
AI Agent 成本工程实战:从 OpenAI Codex 的 8 个“烧 Token“Bug 学起
人工智能·设计模式·微信小程序
律宏阔2 天前
微信小程序使用 Orval + OpenAPI 自动生成接口:Axios 兼容踩坑记录
前端·微信小程序
律宏阔2 天前
微信小程序集成 TDesign 完整记录:解决 NPM packages not found
前端·微信小程序