fix:实现pinia数据持久化
This commit is contained in:
@@ -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
|
||||
|
||||
16
src/store.js
16
src/store.js
@@ -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'],
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user