How the mutations of vuex calls getter? internally

export default new Vuex.Store({
  state: {
    cart_list:[1,2,3],
  },
  getters: {
    total: state => {
      var total = state.cart_list[0]+state.cart_list[1]+state.cart_list[2];
      return total;
    }
  },
  mutations: {
    get_total (state) { 
      console.log(">>>>>: getters>total ?");
    }
  }
})

my current implementation is to use one of the called components:

this.$store.commit("get_total",this.$store.getters.total);

is it right to pass in total?

Mar.20,2021

getter is equivalent to the calculation property of state , and mutation is used to modify state .
it is not a correct operation for mutation to modify getter directly.


this.getters.total (state)
this is an internal call within an object


you can pass the getter you want to use through action's context.getters ('getterName',obj) through action's context.getters (' getterName',obj) to obj as a parameter when submitting the getter via action.

Menu