ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## useLocalStorage 本地存储 ``` const timeago = useLocalStorage("abc") timeago.value="adsasd" ``` ## useSessionStorage 本地存储 ``` const timeago = useSessionStorage("abc") timeago.value="adsasd" ``` ## useStorage ``` import { useStorage } from '@vueuse/core' // bind object const state = useStorage('my-store', { hello: 'hi', greeting: 'Hello' }) // bind boolean const flag = useStorage('my-flag', true) // returns Ref<boolean> // bind number const count = useStorage('my-count', 0) // returns Ref<number> // bind string with SessionStorage const id = useStorage('my-id', 'some-string-id', sessionStorage) // returns Ref<string> // delete data from storage state.value = null ``` ## useStorageAsync 异步存储 ``` const id = useStorageAsync('my-id', 'initialValue', sessionStorage) // returns Ref<string> id.value="asdsad" ``` ## Merge Defaults ``` localStorage.setItem('my-store', '{"hello": "nihao"}') const state = useStorage( 'my-store', { hello: 'hi', greeting: 'hello' }, localStorage, { mergeDefaults: true } // <-- ) console.log(state.hello) // 'nihao', from storage console.log(state.greeting) // 'hello', from merged default value ``` ## Custom Serialization