Skip to content

Commit

Permalink
fix: 修复转储超限问题(不知道之前在想什么)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZvonimirSun committed Nov 13, 2024
1 parent 1a679c0 commit 1a48e27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -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(
{
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/PiniaPersist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ async function createPiniaPersist<S extends StateTree = StateTree>(pluginOptions
}
}

// 转储到 sessionStorage
sessionStorage.clear()
// 转储到内存
const tmpStorage: any = {}
const promiseList: Array<Promise<void>> = []
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)
}
})())
}
Expand All @@ -89,10 +89,10 @@ async function createPiniaPersist<S extends StateTree = StateTree>(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)
}
Expand Down

0 comments on commit 1a48e27

Please sign in to comment.