当前位置:网站首页>Mini Program - Global Data Sharing
Mini Program - Global Data Sharing
2022-07-31 00:32:00 【like feynman%】
1. What is global data sharing
Global data sharing (also known as: state management) is to solve the problem of data sharing between components.Common global data sharing schemes in development include: Vuex, Redux, Mobx, etc. 
2. Global data sharing scheme in applet
You can use mobx-miniprogram with mobx-miniprogram-bindings to achieve global data sharing.of which
- modx-miniprogram is used to create a Store instance object
- mobx-miniprogram-bindings are used to Bind the shared data or methods in the Store to components or pages for use
3. Install Mobx package

Note: After installing Mobx-related packages, remember to delete the miniprogram-npm directory and re-build npm
4. Create Mobx Store instance

//In this js file, it is specially used to create an instance object of Storeimport {observable} from 'mobx-miniprogram'export const store = observable({//data fieldnumA:1,numB:2,//computed propertygetsum(){return this.numA+this.numB},//actions method, used to modify the data in the storeupdataNum1:action(function (step){ this.numA += step}),updataNum2:action(function (step){ this.numB += step}),})5. Bind the members in the store to the page
//Page jsimport { createStoreBindings } from 'mobx-miniprogram-bindings'import { store } from '../../store/store'onLoad: function (options) {this.storeBindings = createStoreBindings(this,{store,//data sourcefields:['numA','numB','sum'],actions:['updateNum1']})},onUnload: function () {//Uninstall this storethis.storeBindings.destroyStoreBindings()},//Page wxml{{numA}}+{{numB}} = {{sum}} numA+1 numA-1 //page jsbtnHandler1(e){// console. log(e)this.updateNum1(e.target.dataset.step)},6. Bind the store member to the component
import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'import { store } from '../../store/store'Component({/*** Component property list*/behaviors:[storeBindingsBehavior],//Automatic binding through storeBindingsBehavior//I don't know where storeBindings came fromstoreBindings:{store,fields:{//fields cannot be written incorrectly, otherwise it will not rendernumA:()=>store.numA,//The first way to bindnumB:(store)=>store.numB,//The second way of bindingSum:'sum'//The third way of binding},actions:{updateNum2:'updateNum2'}},})Using members from Store in components
//Group price.wxml structure{{numA}}+{{numB}}={{sum}} numB+1 numB-1 //List of methods of the componentmethods: {btnHandler2(e){this.updateNum2(e.target.dataset.step)}}边栏推荐
- 【多线程】
- 分布式系统的一致性与共识(1)-综述
- Understand from the 11 common examples of judging equality of packaging types in the written test: packaging types, the principle of automatic boxing and unboxing, the timing of boxing and unboxing, a
- 【愚公系列】2022年07月 Go教学课程 015-运算符之赋值运算符和关系运算符
- 【愚公系列】2022年07月 Go教学课程 016-运算符之逻辑运算符和其他运算符
- xss绕过:prompt(1)
- [Tang Yudi Deep Learning-3D Point Cloud Combat Series] Study Notes
- Kotlin协程:协程上下文与上下文元素
- Optimization of aggregate mentioned at DATA AI Summit 2022
- MySQL triggers
猜你喜欢

unity2D横版游戏教程4-物品收集以及物理材质

消息队列存储消息数据的MySQL表设计

Encapsulate and obtain system user information, roles and permission control

Steven Giesel 最近发布了一个由5部分内容组成的系列,记录了他首次使用 Uno Platform 构建应用程序的经验。

How to adjust Chinese in joiplay simulator
![[In-depth and easy-to-follow FPGA learning 13---------Test case design 1]](/img/1c/a88ba3b01d2e2302c26ed5f730b956.png)
[In-depth and easy-to-follow FPGA learning 13---------Test case design 1]

Shell script if statement

Understand from the 11 common examples of judging equality of packaging types in the written test: packaging types, the principle of automatic boxing and unboxing, the timing of boxing and unboxing, a

加密传输过程
Go 学习笔记(84)— Go 项目目录结构
随机推荐
MySQL笔记下
DNS resolution process [visit website]
Gabor filter study notes
MySQL triggers
firewalld
Shell编程之条件语句
joiplay模拟器不支持此游戏类型怎么解决
Bypass of xss
Consistency and Consensus of Distributed Systems (1) - Overview
unity2D横版游戏教程4-物品收集以及物理材质
DATA AI Summit 2022提及到的对 aggregate 的优化
Go study notes (84) - Go project directory structure
WEB安全基础 - - -漏洞扫描器
ELK部署脚本---亲测可用
After writing business code for many years, I found these 11 doorways, which only experts know
MySQL master-slave replication and read-write separation script - pro test available
Niuke.com question brushing training (4)
web漏洞之需要准备的工作
How to install joiplay emulator rtp
How to import game archives in joiplay emulator