import { useStore as originUseStore, Store,mapState, mapGetters, mapMutations, mapActions } from 'vuex';
import { RootState } from '@/store';
import { Getters, Dispatch, Commit } from '@/store/helper';
import { computed } from 'vue';
/**
*
* @param mapperFn 传入的map辅助函数,mapState, mapGetters, mapActions, mapMutations
* @param mapper 方法或者属性的名字,actions或者mutations或者getter的函数名,state的属性名字
* @param module 开启命名空间后的模块名
* @resultFn {
{}} 返回数组,数组内容为fn函数,fn函数为每个属性所对应的map辅助函数
*/
const hooks = (mapperFn, mapper, module) => {
const store = useStore(); // 引入vuex中的useStore函数
const resultFn = {};
let mapData = {};
if (module) { // 判断是否存在命名空间,如果存在则绑定
mapData = mapperFn(module, mapper);
} else {
mapData = mapperFn(mapper);
}
Object.keys(mapData).forEach( item => {
const fn = m
vue3使用替换...mapAction方案
最新推荐文章于 2023-07-28 15:18:47 发布