first commit
This commit is contained in:
15
app/plugins/04.cart-persist.client.ts
Normal file
15
app/plugins/04.cart-persist.client.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useCartStore } from '~/stores/cart';
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const cartStore = useCartStore();
|
||||
const storageKey = cartStore.getStorageKey();
|
||||
|
||||
cartStore.hydrateFromStorage(localStorage.getItem(storageKey));
|
||||
|
||||
cartStore.$subscribe(
|
||||
() => {
|
||||
localStorage.setItem(storageKey, cartStore.toStoragePayload());
|
||||
},
|
||||
{ detached: true }
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user