鍍金池/ 問答/HTML/ vuex 使用getters出現(xiàn)的問題?

vuex 使用getters出現(xiàn)的問題?

//store/index.js
const store = new Vuex.Store({
  state: {
    count: 1
  },
  mutations: {
    changCount (state, index) {
      state.count = index
    }
  },
  getters: {
    handleCount (state) {
      return state.count += 100
    }
  }
}) 
//index.vue
<button @click="changCount(2)">{{handlecount}}</button>

computed: {
    ...mapState(['count']),
    handlecount () {
      return this.$store.getters.handleCount
    }
  },
  methods: {
    ...mapMutations(['changCount'])
  }

今天看vuex遇到了一個(gè)問題,點(diǎn)擊button第一次變成了102,再點(diǎn)擊還是102是怎么回事?

回答
編輯回答
伴謊

因?yàn)?getters 不能改變 state

2017年6月21日 03:14