vue-lsd

Plugin to sync vue instance data to localStorage
1,214 3
Install
npm install vue-lsd
Latest Version:1.0.42
License:ISC
Last Updated:Feb 7, 2018
Links: GitHub  ·  npm
Maintainer: napzu

Vue localStorageData(lsd)

Vue-lsd is vue plugin to make saving vue instance data to localStorage.

localStorageData() works exatcly same like vue normal data() except everything is saved between page reloads like magic!

DEMO

TRY IT OUT

Install

Usage npm:

npm install vue-lsd

If you want just quickly use it in browser:

<script src="https://unpkg.com/vue-lsd"></script>
<script>Vue.use(vueLocalStorageData)</script>

Usage

import vueLocalStorageData from 'vue-lsd'
Vue.use(vueLocalStorageData)

export default {
  id: '#app',
  localStorageData() { /* Works exactly same as normal data() */
    return {
      hello: 'Hello',
      deepProp: {
        level1: {
          level2: {
            world: 'world!',
          }
        }
      }
    }
  },
  methods: {
      helloWorld(){
          console.log(this.hello+' '+this.deepProp.level1.level2.world)
      }
  },
  created() { this.helloWorld() }
}

Plugin has some options

Vue.use(vueLocalStorageData,{
  prefix: 'yourOwnLocalStorageKeyPrefix',
  throttle: 500 /* throttle how often values are saved to localStorage */
})

Plugin makes vue watchers to every root key and only saves when change actually happens.

Vue instance data is saved with setItem key: vueLocalStorageData_ + vue instance UID + _dataRootKey but you can override it like this:

export default {
  localStorageData() {
    return {
      lsd_id: 'myOwnStr', /* <-- replaces UID in local storage setItem key */
      lsd_throttle: 200,  /* Custom save throttle for this instance */
      myProp1: 'test'
    }
  }
}

Option override keys lsd_id and lsd_throttle won't appear in vue instance.

Related Packages

vuex-along

Automatically restore vuex state after refreshing the page

10,136 259
vuex-masked-modules

Plugin for working with Vuex. Allows to use localeStorage to store state. It is...

1,001 3
vuex-persist

A Vuex persistence plugin in Typescript

2,829,593 1,645
vue-localstorage

Vue.js localStorage plugin with types support

370,253 669
vue-web-storage

Vue.js plugin for localStorage and sessionStorage

74,878 83

Version History

Version Released License
1.0.42 ISC
1.0.41 ISC
1.0.40 ISC
1.0.39 ISC
1.0.38 ISC