Vuex

Vuex Documentation


Best Practices

Prefer mapState over mapGetters + getters for unmodified state

Some of our existing code uses mapGetters in a view component to execute a getter that looks like:

const getters = {
  foo(state) {
    return state.foo
  }
}


If you encounter this pattern, don’t copy it. You can safely just use mapState there, and use getter functions only when some operation on the raw state is needed.

Prefer mapMutations over mapActions + actions that only commit a single mutation

Similarly, there are some places where a Vuex action has been defined that does nothing other than commit a mutation. You can just call the mutation directly in these cases.

Last modified November 20, 2020: Update grafana guilde (3f24643)