vue当前页面下载
转载 let winOri = window.location.origin;
let _url =
winOri +
`/pdtz/sxbl/sl/bItemAcceptAttachment_downloadZipByAcceptId?acceptId=${this.formId}`;
fetch(_url, {
method: "GET",
headers: {
//"Access-Control-Allow-Origin: *"
["Authorization"]: sessionStorage.getItem("token"),
["Access-Control-Allow-Origin"]: "*",
["Access-Control-Allow-Methods"]: "options",
},
}).then(async (res) => {
const attachment = res.headers.get("Content-Disposition");
console.log(attachment);
if (attachment) {
const attachmentArr = attachment.split("; ");
console.log(attachmentArr);
if (attachmentArr[0] === "attachment") {
const attachmentArrJq = attachmentArr[1].split("=");
const attachmentArrTo = attachmentArrJq[1].substring(
0,
attachmentArrJq[1].length - 1
);
const fileNameUtf8 = attachmentArrTo.substr(1)
if (fileNameUtf8.length > 1) {
const fileName = fileNameUtf8[1];
console.log(fileName);
const fileBlob = await res.blob();
const link = document.createElement("a");
link.download = fileName;
link.style.display = "none";
link.href = URL.createObjectURL(fileBlob);
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href);
document.body.removeChild(link);
}
}
}
});
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
下一篇:第一、二周作业
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章