当一个页面中有很多图片需要下载的时候,同时下载会产生下载超时问题,用到下面方法,小白路过,欢迎多提宝贵意见
// 下载图片
async downImage(value: any) {
let imgRes = "";
var URL = "/hcm/img/down?fileName=" + value.imageName;
await this.$httpService.postData({}, URL).then((res: any) => {
// console.log("res", res);
if (res.code == 0) {
this.imgurl = res.data;
}
imgRes = res.msg;
});
return imgRes;
}
getImg(list: any) {
// let iN = 1;
if (this.iN == 1 && list.length) {
this.arrList = list.slice(0, 2);
} else if (this.iN > 1 && list.length > this.iN) {
let arr: any = list[this.iN];
this.arrList = [arr];
}
if (list.length > this.iN || (list.length == 1 && this.iN == 1)) {
this.arrList.map(async (value: any) => {
let res = await this.downImage(value);
if (res) {
this.iN++;
}
this.getImg(list);
});
}
}
网友评论