vuex 中mapMutations映射为 store.commit 调用

首先在组件中引入vuex的mapMutations方法:

import { mapMutations } from 'vuex'


然后在methods中这样写:

        methods:{
            ...mapMutations( [ 'add','reduce' ] )

        }

在组件中调用的时候这样写:

        <button @click='add'>加</button>

        <button @click='reduce'>减</button>
 

猜你喜欢

转载自blog.csdn.net/weixin_43837268/article/details/89599196