Search code examples
vue.jsvuexnuxt.jsstore

Why is the store state of the vuex not stored in localStorage?


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?


Solution

  • 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.