多平台 uni-app / uni-app-x 生态状态管理库
## 简述 是一个专为 uni-app / uni-app-x 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有变量的状态,并以相应的规则保证状态以一种可预测的方式发生变化。 ## 特点 - 中心化状态管理:使用单一的状态树,即一个全局的 state 对象,使得所有组件都能够访问和修改状态,便于状态的集中管理和维护。 - 可预测的状态变化:状态的变化通过提交 getStore / setStore 来进行。这种变化是同步和可追踪的,便于调试和理解应用的状态变化。 ## 交流反馈 官方QQ群:654105306 ## 源码 [](https://github.com/dengqichang/flower-library/tree/main/uni_modules/flower-store) [](https://github.com/dengqichang/flower-library/tree/main/uni_modules/flower-store) [](https://github.com/dengqichang/flower-library/tree/main/uni_modules/flower-store) [](https://github.com/dengqichang/flower-library/tree/main/uni_modules/flower-store) [](https://github.com/dengqichang/flower-library/tree/main/uni_modules/flower-store) [](https://github.com/dengqichang/flower-library/tree/main/uni_modules/flower-store) ## 兼容性 ### Vue 版本 | Vue2 | Vue3 | | :------: | :------: | | √ | √ | ### uni-app 版本 | app-uvue | app-vue | app-nvue | 各端小程序 | H5 | | :------: | :------: | :------: | :-------: | :-------: | | √ | √ | √ | √ |√ | ### uni-app-x 版本 | android | ios | web | | :------: | :------: | :------: | | √ | √ | √ | ## mixinStore / useStore API 函数的使用方式在下方使用示例中体现,用法均一致。 | 函数 | 描述 | 示例 | | :------: | :------: | :------: | | getState | 获取当前状态值 | getState("test") | | setState | 设置当前状态值 | setState("test", "测试值") | | getStore | 获取缓存值,与 `uni.getStorageSync` 一致 | getStore("test") | | setStore | 设置缓存值,与 `uni.setStorageSync` 一致 | setStore("test", "测试值"); | | getStoreState | 获取当前缓存状态值,同时包含`getState`与`getStore`的功能 | getStoreState("test") | | setStoreState | 设置当前缓存状态值,同时包含`setState`与`setStore`的功能 | setStoreState("test", "测试值"); | ## 使用示例 **注意:**`uni-app-x` 与 `uni-app` 使用方式在于导入的差异,用法一致。 ### uni-app-x 示例 #### 普通模式 ```vue