refactor: simplify useLocalStorage (remove APP_PREFIX) and finalize QR Code tool

This commit is contained in:
2026-02-28 04:05:07 +00:00
parent 2a1897f68d
commit d5d3d37804
2 changed files with 18 additions and 15 deletions

View File

@@ -1,16 +1,20 @@
import { ref, watch } from 'vue'
export function useLocalStorage(key, defaultValue) {
export function useLocalStorage(key, defaultValue, toolPrefix = '') {
// Construct prefixed key: [toolPrefix-]key
const prefixPart = toolPrefix ? `${toolPrefix}-` : ''
const prefixedKey = `${prefixPart}${key}`
// Initialize state from local storage or default value
const storedValue = localStorage.getItem(key)
const storedValue = localStorage.getItem(prefixedKey)
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)
localStorage.removeItem(prefixedKey)
} else {
localStorage.setItem(key, JSON.stringify(newValue))
localStorage.setItem(prefixedKey, JSON.stringify(newValue))
}
}, { deep: true })