关于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' }) }
本文来自博客园,作者:鱼樱前端,转载请注明原文链接:https://www.cnblogs.com/lhl66/p/8261748.html

浙公网安备 33010602011771号