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

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM