React 类型声明:importAll 函数、iconList 数组和 getNameList 函数
const importAll = (r: any): string[] => { const svgs: any = {}; r.keys().map((key: string) => { return (svgs[key] = r(key)); });
return Object.keys(svgs); };
const iconList: string[] = importAll(require.context('./svg', false, /.svg$/));
export const getNameList = (): string[] => { const regex = //icon-( .*?).svg/; return iconList.map((item: string) => item.match(regex)![1]); };
原文地址: https://www.cveoy.top/t/topic/qEVu 著作权归作者所有。请勿转载和采集!