其他分享
首页 > 其他分享> > mapState、mapGetter、mapActions、mapMutations使用方法

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

 

标签:count,...,fn2,fn1,add,mapState,state,mapActions,mapMutations
来源: https://blog.csdn.net/qq_39039128/article/details/87936481