参考链接:https://www.jianshu.com/p/0f4386d19c07
import path from "path"; const getLayerBgs = function () { const imgs: any = []; // 获取所有背景图层 //读取文件的路径 是否遍历文件的子目录 匹配文件正则表达式 const files = require.context("@/assets/layer", false, /\.(png|jpg|jpeg)$/); //files(key).default拿到该模块的vue对象 files.keys().forEach((key) => { const name = path.basename(key); const item = {}; item["imageUrl"] = "@/assets/layer/" + name; item["imageName"] = name; imgs.push(item); }); }; 如果报错参考以下链接:参考链接:https://blog.csdn.net/qq_54089372/article/details/127652316
标签:files,const,name,item,文件夹,asset,key,vue3,path From: https://www.cnblogs.com/gaosj20210301/p/17362663.html