robinvdvleuten / vuex-persistedstate

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

how can i use dynamic key #418

Closed bestRenekton closed 3 years ago

bestRenekton commented 3 years ago

Relevant code or config

createPersistedState({
key:'user1',
...
})

Problem description: when user1 login, we save his data as 'user1' by localstorage then he logout and user2 login so how can we save his data as 'user2' by localstorage ? we want their both data in localstorage,because user1 maybe login next time.

Suggested solution: in vuex module , this can do work, but It's too cumbersome,because we have many module

const state: userModuleState = {
  userInfo: {
    user1:{...}
     user2:{...}
   }
};

so can vuex-persistedstate set dynamic key ?

robinvdvleuten commented 3 years ago

Please ask questions on either StackOverflow or any Vuejs related forum. The issue tracker is for issues only.

paraself commented 2 years ago

The issues is that the documentation does not demonstrate clearly how to change the prefix dynamically after the vuex store is instantiated and createPersistedState is called.