// composables/useLocalStorage.js
import { ref, watch } from 'vue';
export function useLocalStorage(key, initial) {
const saved = localStorage.getItem(key);
const value = ref(saved !== null ? JSON.parse(saved) : initial);
watch(
value,
(newVal) => {
localStorage.setItem(key, JSON.stringify(newVal));
},
{ deep: true } // also fire on nested changes inside objects/arrays
);
return value;
}
Count: {{ count }}