vue-component-persist

Persist data in localStorage or anywhere for Vue.js apps.


License
MIT
Install
npm install vue-component-persist@1.1.4

Documentation

vue-component-persist

Persist data in localStorage or anywhere for Vue.js apps

Install

yarn add vue-component-persist

Usage

import Persist from 'vue-component-persist'

Vue.use(Persist)

new Vue({
  template: '<input v-model="text" v-if="shown" />',

  data: {
    text: '',
    shown: false
  },

  persist: {
    text: 'persist-key:text',
    shown: {
      key: 'persist-key:shown',
      expiration: 1000 * 60
    }
  }
})

Then the data of text and shown will be stored at localStorage and kept in sync.

API

Vue.use(Persist, [options])

options

read

Type: function
Default: k => localStorage.getItem(k)

The function we use to get stored data.

write

Type: function
Default: (k, v) => localStorage.setItem(k, v)

The function we use to store data.

clear

Type: function
Default: k => localStorage.removeItem(k)

The function we use to clear data in store.

Original author

vue-persist © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

egoistian.com · GitHub @egoist · Twitter @rem_rin_rin