const req = require.context('@/components/xxx/image', false, /\.png$/);
const requireAll = (requireContext: __WebpackModuleApi.RequireContext) => requireContext.keys();
const re = /\.\/(.*)\.png/;
export type Icon = { name: string; icon: string };
const iconsMap = new Map<string, Icon>();
const icons = requireAll(req).map((e) => {
const icon = req(e);
iconsMap.set(e.match(re)![1], {
name: e.match(re)![1],
icon: icon,
});
return {
name: e.match(re)![1],
icon: icon,
};
});
export { icons, iconsMap };
图片懒加载,动态获取图片
最新推荐文章于 2024-08-25 14:43:46 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)