feat: implement url cleaner tool, local storage persistence and extension integration
This commit is contained in:
18
src/composables/useLocalStorage.js
Normal file
18
src/composables/useLocalStorage.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
export function useLocalStorage(key, defaultValue) {
|
||||
// Initialize state from local storage or default value
|
||||
const storedValue = localStorage.getItem(key)
|
||||
const data = ref(storedValue ? JSON.parse(storedValue) : defaultValue)
|
||||
|
||||
// Watch for changes and update local storage
|
||||
watch(data, (newValue) => {
|
||||
if (newValue === null || newValue === undefined) {
|
||||
localStorage.removeItem(key)
|
||||
} else {
|
||||
localStorage.setItem(key, JSON.stringify(newValue))
|
||||
}
|
||||
}, { deep: true })
|
||||
|
||||
return data
|
||||
}
|
||||
Reference in New Issue
Block a user