复制import{ mapState, mapGetters, useStore, createNamespacedHelpers }from'vuex';import{ computed }from'vue';/** * *@param{Object|Array} data 数据 *@param{String} type map类型:'mapState' 'mapGetters' *@param{String} module 模块名字 */exportfunctionuseMapStore(data, type,module) {conststo...
由于在vue3 compositionApi中 setup函数无法获取this,在使用vuex的时候获取this.$store.state.xx会比较繁琐,而vuex中的函数mapState返回值为函数类型,无法使用computed直接返回具体的数值(会提示缺失$stote),考虑使用bind函数重新封装mapState返回的函数,通过bind指定一个绑定$store,参数为useStore,从而变成可以被computed...
useState和useGetters两个函数相似度很高,在进一下封装 // useMapper.js import { computed } from "vue"; import { useStore } from "vuex"; export default function useMapper(mapper, mapFn) { const store = useStore(); const storeStateFns = mapFn(mapper); const storeState = {}; Object.keys...