importAll 引入所有文件
/******** importAll.js *********/
let cache = {};
export default function importAll(r){
r.keys().forEach(key => cache[key] = r(key));
return cache;
}
/******** 使用 *********/
const cache1 = importAll(require.context('../assets/img1', true, /\.png|\.jpg));
const cache2 = importAll(require.context('../assets/img2', true, /\.png|\.jpg));
const cache = Object.assign(cache1, cache2);
let imgArr = [];
for(const key in cache){
if(cache.hasOwnProperty(key)){
imgArr.push(cache[key]);
}
}