0.1.0 • Published 7 years ago
vue-localstore v0.1.0
vue-localstore
Vue plugin for localForage. Binds localForage to Vue instances as $localstore.
Installation
Install vue-localstore with npm (or alternatively yarn):
npm --save install vue-localstoreThen add it to Vue in your main.js:
const VueLocalStore = require('vue-localstore');
Vue.use(VueLocalStore);Usage
Since localForage is exposed directly to this.$localstore, you can use both the callback-based and Promsie-based API.
this.$localstore.setItem('key', 'value').then(function () {
    return this.$localstore.getItem('key');
}).then(function (value) {
    // we got our value
}).catch(function (err) {
    // we got an error
});Configuration
When adding vue-localstore to Vue, you can pass a configuration object. This causes $localstore to point to a configured localForage instance (see localForage documentation sections Configuration and Multiple instances):
const VueLocalStore = require('vue-localstore');
Vue.use(VueLocalStore, {
    driver      : localforage.WEBSQL, // Force WebSQL; same as using setDriver()
    name        : 'myApp',
    version     : 1.0,
    size        : 4980736, // Size of database, in bytes. WebSQL-only for now.
    storeName   : 'keyvaluepairs', // Should be alphanumeric, with underscores.
    description : 'some description'
});0.1.0
7 years ago