a标签模拟文件下载
1.像PDF、png、jpg等浏览器可以打开的文件,需要在文件地址上加上类似header的字段
const downloadFun = (data: any) => {
let a = document.createElement('a');
a.style.display = 'none';
a.href = data.url + '?response-content-type=application/octet-stream';
// a.target='_blank'
a.setAttribute('download', data.name + '.' + data.type)
a.download = data.url;
document.body.appendChild(a);
a.click()
a.remove()
}
2.a标签模拟批量下载文件,通常只会下载最后一个文件,需要加上定时器
const downloadAll = () => {
let speed = 200
tableData.value.forEach((ele: any, index: number) => {
let timer = setTimeout(() => {
downloadFun(ele)
clearTimeout(timer)
}, index * speed)
})
}
1万+

被折叠的 条评论
为什么被折叠?



