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