From 553a736167e5f586cf012ce7da7938f13a985a01 Mon Sep 17 00:00:00 2001 From: luoxiaoting <1150143576@qq.com> Date: Thu, 28 Apr 2022 10:51:44 +0800 Subject: [PATCH] fix:modify persistence doesn't work well when using multiple pinia stores at the same time --- src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1195e74..e9a0870 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ -import { PiniaPluginContext } from 'pinia' +import { PiniaPluginContext } from 'pinia' +import nextTick from 'vue' export interface PersistStrategy { key?: string; storage?: Storage; @@ -36,7 +37,7 @@ export const updateStorage = (strategy: PersistStrategy, store: Store) => { } } -export default ({ options, store }: PiniaPluginContext): void => { +export default async ({ options, store }: PiniaPluginContext): Promise => { if (options.persist?.enabled) { const defaultStrat: PersistStrategy[] = [{ key: store.$id, @@ -55,7 +56,7 @@ export default ({ options, store }: PiniaPluginContext): void => { updateStorage(strategy, store) } }) - + await nextTick() store.$subscribe(() => { strategies.forEach((strategy) => { updateStorage(strategy, store)