關於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'
    })
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM