mapState、mapGetter、mapActions、mapMutations使用方法

import {mapState,mapGetters,mapActions,mapMutations} from 'vuex'

//this.$store.state.xxx  映射
...mapState({
    add:state=>state.add,
    count:state=>state.count
})
//2
...mapState(['add','count']);


...mapGetters(['add','count']);

...mapActions({
    'fn1':'fn1',
    'fn2':'fn2',
});
...mapActions(['fn1','fn2'])

this.$store.dispatch('fn1')  ===  this.fn1

...mapMutations({
    'fn1':'fn1',
    'fn2':'fn2',
});
...mapMutations(['fn1','fn2'])

this.$store.commit('fn1')  ===  this.fn1

猜你喜欢

转载自blog.csdn.net/qq_39039128/article/details/87936481