Skip to content

Commit

Permalink
fix(PiniaPersist): 修复数据异常
Browse files Browse the repository at this point in the history
  • Loading branch information
ZvonimirSun committed Mar 22, 2024
1 parent cb9e2fa commit 1388860
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/plugins/PiniaPersist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ async function createPiniaPersist<S extends StateTree = StateTree>(pluginOptions
const data = getState(key, true)
store.$patch(merge({}, store.$state, serializer ? serializer.deserialize(data) : data))

// let flag = true
// 更新数据
const updateState = debounce(() => {
_mutex.enqueue(setState(key, serializer ? serializer.serialize(store.$state) : store.$state).catch((e) => {
Expand All @@ -143,7 +142,14 @@ async function createPiniaPersist<S extends StateTree = StateTree>(pluginOptions
_mutation: SubscriptionCallbackMutation<StateTree>,
) => {
if (_mutation.storeId === 'main') {
if (!Array.isArray(_mutation.events) && _mutation.events.key === 'clearOfflineCacheTag') {
let flag = false
if (_mutation.events && !Array.isArray(_mutation.events) && _mutation.events.key === 'clearOfflineCacheTag') {
flag = true
}
else if (store.$state.clearOfflineCacheTag) {
flag = true
}
if (flag) {
localStore.clear().then(() => {
window.location.reload()
})
Expand Down

0 comments on commit 1388860

Please sign in to comment.