On this page
useIDBKeyval
Category | @Integrations |
---|---|
Export Size | 675 B |
Package | @vueuse/integrations |
Last Changed | 2 weeks ago |
Wrapper for idb-keyval
.
Install idb-keyval as a peer dependency
npm install idb-keyval
Usage
import { useIDBKeyval } from '@vueuse/integrations/useIDBKeyval'
// bind object
const { data: storedObject, isFinished } = useIDBKeyval('my-idb-keyval-store', { hello: 'hi', greeting: 'Hello' })
// update object
storedObject.value.hello = 'hola'
// bind boolean
const flag = useIDBKeyval('my-flag', true) // returns Ref<boolean>
// bind number
const count = useIDBKeyval('my-count', 0) // returns Ref<number>
// delete data from idb storage
storedObject.value = null
Type Declarations
export interface UseIDBOptions extends ConfigurableFlush {
/**
* Watch for deep changes
*
* @default true
*/
deep?: boolean
/**
* On error callback
*
* Default log error to `console.error`
*/
onError?: (error: unknown) => void
/**
* Use shallow ref as reference
*
* @default false
*/
shallow?: boolean
/**
* Write the default value to the storage when it does not exist
*
* @default true
*/
writeDefaults?: boolean
}
/**
*
* @param key
* @param initialValue
* @param options
*/
export declare function useIDBKeyval<T>(
key: IDBValidKey,
initialValue: MaybeRefOrGetter<T>,
options?: UseIDBOptions
): {
data: RemovableRef<T>
isFinished: Ref<boolean>
}
Source
© 2019-present Anthony Fu
Licensed under the MIT License.
https://vueuse.org/integrations/useIDBKeyval/