Files
nuxtfiber/app/plugins/04.cart-persist.client.ts
Beyhan Oğur 7b2b27a42c first commit
2026-04-26 22:18:17 +03:00

16 lines
412 B
TypeScript

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 }
);
});