鍍金池/ 問答/網絡安全  HTML/ vuex的mutations如何內部調用getter?

vuex的mutations如何內部調用getter?

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 ?");
    }
  }
})

我現(xiàn)在的實現(xiàn)方法是,在調用的組件中用了一個:

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

把total傳入,這樣做是對的么?

回答
編輯回答
舊城人

getter 相當于 state 的計算屬性,mutation 是用來修改 state 的。
mutation 直接修改 getter 不是正確操作啊。

2017年8月22日 10:05