ppms-uni-vue3-huertian/src/stores/persist.ts
HoshinoSuzumi ceb9636b42 feat: 添加pinia状态管理库和Tabbar组件
- 添加pinia状态管理库和Tabbar组件
- 引入axios和fant-axios-adapter
- 在main.ts中使用pinia和persist插件
- 在App.vue中修改标题
- 在useUser.ts中添加logout方法
- 添加persist.ts文件
- 修改page-wrapper.vue和TabBar.vue中的代码
- 修改index.vue和login.vue中的代码
2024-09-19 00:13:56 +08:00

18 lines
546 B
TypeScript

import type { PiniaPluginContext } from "pinia";
import { deepClone } from "wot-design-uni/components/common/util";
export function persist({ store }: PiniaPluginContext) {
// 暂存State
let persistState = deepClone(store.$state);
// 从缓存中读取
const storageState = uni.getStorageSync(store.$id);
if (storageState) {
persistState = storageState;
}
store.$state = persistState;
store.$subscribe(() => {
// 在存储变化的时候将store缓存
uni.setStorageSync(store.$id, deepClone(store.$state));
});
}