下载url、fileName文件名
download(url,fileName){
const link = document.createElement('a');
// 将链接地址url转成blob地址,
fetch(url).then(res => res.blob()).then(blob => {
link.href = URL.createObjectURL(blob)
// 下载文件的名称
link.download =fileName;
document.body.appendChild(link)
link.click()
//在资源下载完成后 清除 占用的缓存资源
window.URL.revokeObjectURL(link.href);
document.body.removeChild(link);
});
}
前端下载文件,后端返回的时url,根据url下载文件
最新推荐文章于 2024-06-26 09:56:59 发布