fix:实现pinia数据持久化

This commit is contained in:
2026-05-14 17:13:29 +08:00
parent 5c36af30cd
commit bf3f3a3afe
4 changed files with 23 additions and 8 deletions

View File

@@ -1,10 +1,12 @@
import { createSSRApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import App from './App.vue'
export function createApp() {
const app = createSSRApp(App)
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
app.use(pinia)
return {
app

View File

@@ -154,14 +154,14 @@ export default defineStore("store", {
},
},
// 开启数据持久化
// 数据持久化via pinia-plugin-persistedstate
// 仅持久化 user 和 device身份凭证需在冷启动时恢复如从分享链接进入
// config、game 等运行时状态不持久化,每次联网后重新拉取
persist: {
enabled: true,
strategies: [
{
storage: uni.getStorageSync,
paths: ["user", "device", "config"], // 只持久化用户信息
},
],
storage: {
getItem: (key) => uni.getStorageSync(key),
setItem: (key, value) => uni.setStorageSync(key, value),
},
paths: ['user', 'device'],
},
});