admin管理员组文章数量:1567527
核心思路:浏览器是限制瞬间下载10条,所以每下载10条让他休息会就行,用async await实现
小坑:forEach只支持同步,不支持异步,所以不能在forEach里使用async
downFile(url){
let a = document.createElement('a')
console.log(this.downUrl+url)
// window.location.href = this.downUrl+url;
a.setAttribute('href', this.downUrl+url)
a.setAttribute('download', url)
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
},
pause(msec) { // 异步暂停函数
return new Promise(
(resolve, reject) => {
setTimeout(resolve, msec || 1000);
}
);
},
// 批量下载弹窗
async batchDown(){
if(this.currentSelectList.length == 0){
this.$tMsgbox.info({
contentTitle: '请先选择一条数据',
contentBody: ''
});
return ;
}
// let downFileList = [];
let count = 0; // 已下载的文件数
for(let file of this.currentSelectList){
this.downFile(file.erptFilePath)
if(++count >= 10){
await this.pause(1000);
count = 0;
}
}
},
版权声明:本文标题:a标签实现批量下载,谷歌浏览器限制下载10条问题解决 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1725899160a1047979.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论