vue中mapGetters和...mapGetters


  

根据文档介绍 https://vuex.vuejs.org/zh-cn/... 和看了 http://www.imooc.com/article/...

  export default { computed: { ...mapGetters([ 'singer' ]), } .... } 

最终会转换成

  export default { computed: { singer() { return this.$store.state.singer } } ... } 

扩展运算符...可以将数组转换成参数序列,但是这个地方是在函数前面使用了,根据源码mapGetters函数返回的这个对象。
所以不太明白

 

 

vuex.common.js里面定义的mapGetters:

var mapGetters = normalizeNamespace(function (namespace, getters) {
var res = {};
normalizeMap(getters).forEach(function (ref) {

var key = ref.key; var val = ref.val; val = namespace + val; res[key] = function mappedGetter () { if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) { return } if (process.env.NODE_ENV !== 'production' && !(val in this.$store.getters)) { console.error(("[vuex] unknown getter: " + val)); return } return this.$store.getters[val] }; // mark vuex getter for devtools res[key].vuex = true;

});
return res
});

 

参考文档: https://www.cnblogs.com/websmile/p/8328138.html

 
 
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM