function download(res) { // 错误处理 if (res.data.type == "application/json") { let reader = new FileReader(); reader.readAsText(res.data, 'utf-8'); reader.onload = function () { let json_data = JSON.parse(reader.result); Message({ showClose: true, message: json_data.Message, type: "error" }); } return; } // 下载处理 let filename = "content-disposition" in res.headers ? decodeURIComponent( res.headers["content-disposition"] .split(";")[1] .split("=")[1] .replace(/"/g, "") ) : "下载文件"; try { if (window.navigator.msSaveOrOpenBlob) { navigator.msSaveBlob(res.data, filename); } else { let blob = new Blob([res.data], { type: "application/vnd.ms-excel" }); let url = URL.createObjectURL(blob); let link = document.createElement("a"); link.setAttribute("href", url); link.setAttribute("download", filename); link.style.display = "none"; document.body.appendChild(link); link.click(); URL.revokeObjectURL(url); // 释放URL 对象 document.body.removeChild(link); } } catch (err) { // console.log(err) } }
上面是“ajax接口返回的文件流数据处理方法介绍”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_4121.html
workflows工作流
一座巨大的野兽派建筑漂浮在热带风景中的贫民
一位美丽的女士在座机上讲话ComfyUI工作流
穿着蘑菇帽的小蚂蚁探险家ComfyUI工作流
一个由红色玻璃制成的女性形状的破碎雕塑
一个20岁丰满的女孩ComfyUI工作流
一尊白玉佛像ComfyUI工作流
一条赤壁龙从蛋中孵化出来ComfyUI工作流
金色玫瑰花comfyui工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!