//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"])
}
Today, I encountered a problem with vuex. Clicking button becomes 102 for the first time. What"s going on again?