2

When I refresh the page, the store's state is all gone.

This is very inconvenient when programming.

When I looked up, there was a module called vuex-persist, which stores the state of vuex in localStorage.

  1. Why doesn't vuex store the state of vuex by default in cookie or localStorage?

  2. And, will there be any side effects of storing the state of the store using the vuex-persist module?

Rebbeca
  • 1,587
  • 2
  • 10
  • 12
  • 1. Why should it? It wasn't advertised as persistent state and it's not universally used as persistent state. If your only scenario of use is persistent state on client side then use vuex-persist, this is what it is for. 2. There will be if persistent state is not needed. – Estus Flask Apr 14 '20 at 12:56
  • Then, isn't there any side effect if I use vuex-persist to save only a part of the state? – Rebbeca Apr 14 '20 at 13:05
  • This cannot be considered in general, totally depends on your case. If your app will stop working as expected because you used stale local data in some place instead of fetching it from a server, consider it a side effect. – Estus Flask Apr 14 '20 at 13:27

1 Answers1

0

Why doesn't vuex store the state of vuex by default in cookie or localStorage?

Vuex is a state management library. It most of the cases, the state will be partially filled from an API or a database. It's not Vuex's responsibility to persist that state.

Will there be any side effects of storing the state of the store using the vuex-persist module?

It depends on what your application is, but it should not

Just be careful about the size of the local storage, which is quite large but not infinite.

Boris K
  • 1,469
  • 9
  • 29