handleDownload = () => {
const url = 'http://xxxxxxxxxxxx'; // url为地址,按回车后会重定向到图片的地址
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(response => response.json())
.then(resp => {
if (resp.bean) {
// resp.bean为图片真实地址
const aEle = document.createElement('a');
document.body.appendChild(aEle);
aEle.style.display = 'none';
aEle.href = resp.bean;
aEle.download = '这个是文件名';
aEle.click();
document.body.removeChild(aEle);
}
})
}
前端:如何在重定向后下载图片
于 2022-08-29 14:13:36 首次发布