-1

I currently have a Vue.js 2 SPA using Vuex for inter-component communication and Vuex-persisted state to persist my shared state.

However, I want to persist a component's local private data.

I tried the package vue-persist and it persists the component data fine, however, the variables are not namespaced and therefore shared between all component instances. I want to persist each component's data separately.

Does anyone know how I can achieve these 2 things in my Vue.js 2.x app?

1) Persistence of my local data (so it survives a browser refresh).
2) The persisted data is not shared with other components (perhaps name-spaced for each component instance?).

Thanks!

Crapicus
  • 214
  • 2
  • 9
  • I use this approach and save to sessionStore: https://stackoverflow.com/questions/43027499/vuex-state-on-page-refresh – Simon Thiel Jun 13 '19 at 08:46

1 Answers1

0

I'm not familiar with vue-persist, but it looks like you can pass a store name as the second argument to $persist. Choose a unique store name for the component instance (this will vary depending on the component).

e.g.

created() {
  this.$persist(['foo'], 'my-comp:' + this.id);
}
Decade Moon
  • 32,968
  • 8
  • 81
  • 101
  • That works perfectly, ignore my previous dumb attempts to get it working - I was just passing my unique id in a ridiculous way. I thank you. – Crapicus Jul 17 '17 at 09:40