export const downloadFileWithIframe = (url, name) => {
const iframe = document.createElement('iframe');
iframe.style.display = 'none'; // 防止影响页面
iframe.style.height = 0; // 防止影响页面
iframe.name = name;
iframe.src = url;
document.body.appendChild(iframe); // 这一行必须,iframe挂在到dom树上才会发请求
// 5分钟之后删除(onload方法对于下载链接不起作用,就先抠脚一下吧)
setTimeout(() => {
iframe.remove();
}, 5 * 60 * 1000);
// console.log(url)
// window.open(url)
};
前端文件下载方法(包含get和post)
于 2024-01-10 16:58:53 首次发布