diff --git a/eslint.config.js b/eslint.config.js index 14bdf53c..f683a31c 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,6 +1,6 @@ // eslint.config.js import antfu from '@antfu/eslint-config' -import autoImport from './.eslintrc-auto-import.json' assert {type: 'json'} +import autoImport from './.eslintrc-auto-import.json' with {type: 'json'} export default antfu( { diff --git a/src/plugins/PiniaPersist.ts b/src/plugins/PiniaPersist.ts index a641a30b..f3d6566b 100644 --- a/src/plugins/PiniaPersist.ts +++ b/src/plugins/PiniaPersist.ts @@ -73,14 +73,14 @@ async function createPiniaPersist(pluginOptions } } - // 转储到 sessionStorage - sessionStorage.clear() + // 转储到内存 + const tmpStorage: any = {} const promiseList: Array> = [] for (const key of keys) { promiseList.push((async () => { const data = await localStore.getItem(key) if (data != null) { - sessionStorage.setItem(key, JSON.stringify(data)) + tmpStorage[key] = JSON.stringify(data) } })()) } @@ -89,10 +89,10 @@ async function createPiniaPersist(pluginOptions // 获取state的值 const getState = (key: string, clear: boolean) => { - const data = sessionStorage.getItem(key) + const data = tmpStorage[key] if (data != null) { if (clear) { - sessionStorage.removeItem(key) + delete tmpStorage[key] } return JSON.parse(data) }