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();

}

 
posted @ 2017-10-21 10:33  daidai201  阅读(3312)  评论(0编辑  收藏  举报