I've seen a few answers on StackOverflow, people asked about how to use it. But none of them helped. Here's my code:
async fileDownload(id) {
this.isLoading = true;
try {
const res = await downloadApi.downloadById(id);
console.log(res.headers);
let blob = new Blob([res.data], {type: res.headers['content-type']});
let link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'file';
link.click();
URL.revokeObjectURL(link.href);
} catch (e) {
console.error(e);
}
this.isLoading = false;
},
the function, request, and response are working fine. But when I download the file, the file doesn't open.
Request header:
the response data: ...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…