vue之Mutations 理解

commit:提交可以在组件中使用 this.$store.commit('xxx') 提交 mutation,或者使用 mapMutations 辅助函数将组件中的 methods 映射为 store.commit 调用(需要在根节点注入 store)。

 
import { mapMutations } from 'vuex'

export default {

methods: {
  ...mapMutations([
    'increment'
]) // 映射 this.increment() 为
this.$store.commit('increment')]),
    ...mapMutations({ add: 'increment'}) // 映射 this.add() 为 this.$store.commit('increment')

如何使用呢
第一种
<button @click="increment"></button>

第二种

  mounted(){

     this.increment();

}

 
原文地址:https://www.cnblogs.com/daiwenru/p/7703944.html