README
@storage-js/vue-localforage
A plugin wrapped from localForage for Vue.js.
Installation
Install using npm
# install it via npm
npm install @storage-js/vue-localforage --save
Install using yarn
# install it via yarn
yarn add @storage-js/vue-localforage
Direct usage with html
<!-- insert the vue core before it -->
<script src="https://unpkg.com/@storage-js/vue-localforage"></script>
Usage
// register the plugin on vue
import VueLocalforage from '@storage-js/vue-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
(optional) instances
- Default:
[]
You can create multiple instances.
(optional) driver
- Default:
[localforage.INDEXEDDB, localforage.WEBSQL, localforage.LOCALSTORAGE]
The preferred driver(s) to use.
(optional) name
- Default:
localforage
The name of the database.
(optional) size
- Default:
4980736
The size of the database in bytes.
(optional) storeName
- Default:
keyvaluepairs
The name of the datastore.
(optional) version
- Default:
1.0
The schema version of your database.
(optional) description
- Default: ``
A description of the database.
More informations on LocalForage documentation