16 lines
412 B
TypeScript
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 }
|
|
);
|
|
});
|