如果后端明确告诉你返回的是base64,那请求头就不用带responseType: “blob”,和普通的接口一样发送就行
await materialsFile({ id: proxy.$route.query.id }).then((res) => {
if (res) {
const raw = window.atob(res.data);
const rawLength = raw.length;
const uInt8Array = new Uint8Array(rawLength);
for (let i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
const link = document.createElement("a");
let blob = new Blob([uInt8Array]);
link.style.display = "none";
link.href = URL.createObjectURL(blob);
link.setAttribute(
"download",
`${userForm.value.name}-${userForm.value.phone}.zip`
);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(link.href);
}
});