2022-12-14 解决下载txt浏览器直接打开的问题
2022-12-13 本文已影响0人
遗忘的灬誓言
const fileDownload = (item: Object) => {
console.log(item.recordName);
let url = SYSTEM_CONFIG.services.BASE_API + item.url;
window.fetch(url).then(res => {
return res.blob()
}).then(blob => {
let a = document.createElement('a');
a.href = window.URL.createObjectURL(blob);
a.setAttribute('download', item.recordName);
a.target = '_blank';
a.style.display = 'none';
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
})
}