zoukankan      html  css  js  c++  java
  • 关于mapState和mapMutations和mapGetters 和mapActions辅助函数的用法及作用(二)-----mapMutations

    在组件中提交Mutations:

    import { mapState, mapMutations } from 'vuex'
    export default {
        data() {
            return {
                msg: "vuex要点"
            }
        },
        store,
        computed: mapState([
            'count'
        ]),
        // methods: mapMutations([
        //     'add', 'reduce'
        // ]),
    
        //或者
        methods: {
            //如果组件中事件的名称和mutations中方法的名称相同,可以传一个字符串数组
            ...mapMutations([
                'add' //映射 this.add() 为 this.$store.commit('add')
            ]),
            //组件中的事件名和mutations中的方法名不一样,传入对象
            ...mapMutations({
                reduces: 'reduce' //映射 $this.reduces 为 this.store.commit('reduce')
            })
        }
    }

    Mutations必须是同步函数!!!

  • 相关阅读:
    【笔记】Maven使用入门
    【笔记】c++文件
    【笔记】IntelliJ IDEA配置Hibernate
    【HTML5校企公益课】第四天
    【c++习题】【17/4/16】动态分配内存
    C#
    C#
    C#
    C#
    C#
  • 原文地址:https://www.cnblogs.com/lhl66/p/8261719.html
Copyright © 2011-2022 走看看