Skip to content

Instantly share code, notes, and snippets.

@YuraKolesnikov
Created August 15, 2019 13:13
Show Gist options
  • Save YuraKolesnikov/d7c0206930b131041e08857752bd3d34 to your computer and use it in GitHub Desktop.
Save YuraKolesnikov/d7c0206930b131041e08857752bd3d34 to your computer and use it in GitHub Desktop.
vuex-persistedstate performance in modular Vuex
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import { testStorage } from './modules/test'
export default new Vuex.Store({
modules: {
testStorage
}
})
import { TestPlugin } from '../plugins/TestPlugin'
export const testStorage = {
state: {
value: ''
},
mutations: {
changeValue: (state, value) => state.value = value
},
getters: {
getValue: state => state.value
},
actions: {
actionValue: ({state, commit, rootState}) => {
commit('changeValue', 'YEET')
}
},
plugins: [TestPlugin]
}
import VuexPersistedState from 'vuex-persistedstate'
export const TestPlugin = VuexPersistedState({
key: 'test',
storage: window.localStorage,
paths: ['value']
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment