0.0.1-beta.2 • Published 6 years ago

vuex-class-persist v0.0.1-beta.2

Weekly downloads
31
License
ISC
Repository
github
Last release
6 years ago

vuex-class-persist

Note: this project is a wrapper around Vuex-Persist and is not intended to steal any of ChampionSwimmer's code.

Link to Vuex-Persist

Features

  • All features found in Vuex-Persist
  • Ability to persist instances of classes in localStorage

Usage

The usage and creation is all the same as vuex-persist, except you also pass along an array of your classes so vuex-class-persist knows which classes to restore back to after the state has been reloaded from storage.

Steps

Import it

import VuexClassPersistence from 'vuex-class-persist'

Create an object

// You will need to be able to supply an array of your classes
// to ensure they get restored from storage.
const classes = [
  class User { /* Omitted */ },
  class Profile { /* Omitted */ },
  class Example { /* Omitted */ },
  ...
]

const vuexLocal = new VuexClassPersistence({
    storage: window.localStorage
}, classes)

Use it as Vue plugin. (in typescript)

const store = new Vuex.Store<State>({
  state: { ... },
  mutations: { ... },
  actions: { ... },
  plugins: [vuexLocal.plugin]
})

(or in Javascript)

const store = {
  state: { ... },
  mutations: { ... },
  actions: { ... },
  plugins: [vuexLocal.plugin]
}