I’m trying to update an object property inside my localStorage but useStorage
doesn’t update the object if it exists in the store.
in App.vue
:
routeStore.query = {
tab: 'products',
subTab: 1,
search: '',
article: '',
}
console.log(routeStore.query)
console.log(localStorage.query)
useStorage('query', routeStore.query)
console.log(localStorage.query)
console
:
Proxy(Object) {tab: 'products', subTab: 1, search: '', article: ''}
{"tab":"products","subTab":2,"search":"","article":""}
{"tab":"products","subTab":2,"search":"","article":""}
Desired outcome is for query.subTab
to be 1
. Am I doing it wrong?
2
Answers
Ok, so by default useStorage doesn’t sync the default object with localStorage. See here https://vueuse.org/core/useStorage/#merge-defaults
Try using
mergeDefaults
.You should use Merge Defaults option
Here is JSFiddle https://jsfiddle.net/12ctwmzg/