//store/index.js
mutations: {
myIncrease(state){
state.count++
},
myDecrease(state){
state.count--
}
},
//vue
<template>
<div class="home">
<h2>{{this.$store.state.count}}</h2>
<button @click="myIncrease">增加</button>
<button @click="myDecrease">减少</button>
</div>
</template>
<script>
import {mapMutations} from 'vuex'
export default {
name: 'home',
methods:{
...mapMutations(['myIncrease','myDecrease']),
add(){
this.myIncrease()
},
reduce(){
this.myDecrease()
}
},
}
</script>