v-localforage
v2.0.1
Published
A plugin wrapped from localForage for Vue.js.
Downloads
3,669
Maintainers
Readme
v-localforage
A plugin wrapped from localForage for Vue.js.
Installation
Install using npm
# install it via npm
npm install v-localforage --save
Install using yarn
# install it via yarn
yarn add v-localforage
Direct usage with html
<!-- insert the vue core before it -->
<script src="https://unpkg.com/v-localforage"></script>
Usage
// register the plugin on vue
import VueLocalforage from 'v-localforage'
Vue.use(VueLocalforage)
// you can also pass options, check options reference below
Vue.use(VueLocalforage, Options)
Get item
let item = await this.$localforage.getItem(key)
Set item
await this.$localforage.setItem(key, value)
Remove item
await this.$localforage.removeItem(key)
Clear
await this.$localforage.clear()
Gets the length
let length = await this.$localforage.length()
Get the name of a key based on its ID
let k = await this.$localforage.key(keyIndex)
Get the list of all keys
let keys = await this.$localforage.keys()
More informations on LocalForage documentation
Advanced Usage
You can register multiple instances, see below:
Vue.use(VueLocalforage, {
instances: [
{
storeName: 'instance1'
},
{
storeName: 'instance2'
}
]
})
// for instance1
await this.$localforage.instance1.setItem(key, value)
// for instance2
await this.$localforage.instance2.setItem(key, value)
Options
instances
(optional)
- Default:
[]
You can create multiple instances.
driver
(optional)
- Default:
[localforage.INDEXEDDB, localforage.WEBSQL, localforage.LOCALSTORAGE]
The preferred driver(s) to use.
name
(optional)
- Default:
localforage
The name of the database.
size
(optional)
- Default:
4980736
The size of the database in bytes.
storeName
(optional)
- Default:
keyvaluepairs
The name of the datastore.
version
(optional)
- Default:
1.0
The schema version of your database.
description
(optional)
- Default:
''
A description of the database.