How does vuex use getters to manage data in state?

do not understand the use of getters token: null token is also valuable in my localStorage
I write as follows: why is token still null in state after refreshing the page? Is this different from the use of computational properties?

getters.js

export default {
  token (state) {
    if (!state.token) {
      let token = JSON.parse(window.localStorage.getItem("token") || null)
      state.token = token
      return token
    }
  }
}
Jun.05,2022

the only way to change the state in the store of the Vuex is to submit the mutation. It is recommended that you take a closer look at the Vuex documentation.


upstairs positive solution, you can take a look at the document, each usage, getter is only as a state return pre-processing, similar to the concept of decorator.

Menu