根据url地址下载多个文件:
1、通过iframe的方式
const iframe = document.createElement('iframe')
iframe.style.display = 'none' // 防止影响页面
iframe.style.height = 0 // 防止影响页面
iframe.src = item.download_file
document.body.appendChild(iframe) // 这一行必须,iframe挂在到dom树上才会发请求
// 5秒之后删除(onload方法对于下载链接不起作用,就先抠脚一下吧)
setTimeout(() => {
iframe.remove()
}, 5000)
但是此方法可能会存在跨域的问题,如果环境协议为https 而下载地址为http则会报错,需要通过代理的方式解决
2.通过window.open的方式