在mutation中写上自定义的方法,组件中通过 this.$store.commit(“自定义的方法名”) 就可以更新store中的数据和状态
- 直接取值:
<div>{{$store.state.count}}</div> - 通过methods操作值:
addCount(){this.$store.commit('increment')}, - 通过methods传值
addnum(addcounter){ this.$store.commit("addIncrement",addcounter)},