robinvdvleuten / vuex-persistedstate

💾 Persist and rehydrate your Vuex state between page reloads.
https://npm.im/vuex-persistedstate
MIT License
5.77k stars 378 forks source link

Local Storage is not initalizing #25

Closed SmarterPhoneLabs closed 7 years ago

SmarterPhoneLabs commented 7 years ago

Hi Robin, Here is the issue Im having. I installed the package from npm I setup my store.ts (yeah Im one of those TypeScript kids)

import * as Vue from 'vue';
import * as Vuex from 'vuex';
import * as createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex);

export const store  = new Vuex.Store({
    state: {
        AppName : "BillAndTedsExcellentApp",
        UserID: 0,
        Crumb: '',
        GPSInsightToken:'',
        HeaderNavItems : [],
        PageOptions : [] 
    },
    plugins: [createPersistedState()]
});

Then when the app recompiles, when I look in the inspector there is nothing for my app listed under LocalStorage.

I tried specifying a key to use my app name instead of your default.

So, it may just be my lack of understanding here, but does it not automatically serialize the items I have listed in my State?

Thanks, John (YukidamaGame)

robinvdvleuten commented 7 years ago

@SmarterPhoneLabs thanks for using the plugin. At first sight nothing is wrong with your setup. Can you confirm that your state is persisted, e.g. can you see the changes you made to the state object in your app upon recompiling? It could be possible that you bump in - what looks like - an issue with the devtools where localstorage appears to be empty when using hot reloading.

SmarterPhoneLabs commented 7 years ago

I can confirm that my values are no persisting. Would be happy to do a screen share or remote session if you would like to see first hand

SmarterPhoneLabs commented 7 years ago

So I figured the issue out with Robin. I was not using Mutations on my state, and thus the values were not properly writing. Once I switched over, all good