关于mapState和mapMutations和mapGetters 和mapActions辅助函数的用法及作用(三)-----mapGetters

简单的理解:

const getters = {
    newCount: function(state){
        return state.count += 5;
    }
}
---------------------------------------
组件中获取:
methods: {
    newCount: function(){
        return this.store.getters.newCount;
    }
}
------------------------------------------
import { mapGetters } from 'vuex'
computed: {
    ...mapGetters(['count'])
}
当getters中的属性和组件节点的属性相同时可以通过mapGetters辅助函数的数组参数来赋值

如果你想将一个 getters 属性另取一个名字,可以使用对象形式:
computed: {
    ...mapGetters({
        counts: 'count'
    })
}

 

posted @ 2018-01-10 23:26  蓝色帅-橙子哥  阅读(1923)  评论(0编辑  收藏  举报