当前位置: 首页 > Web前端 > vue.js

vuefilestreamdownloadie,googlecompatible

时间:2023-03-31 18:08:57 vue.js

///从响应的headers中获取文件名,后端设置的文件名response.setHeader("Content-disposition","attachment;filename=xxxx.docx");varpatt=newRegExp("文件名=([^;]+\\.[^\\.;]+);*");varcontentDisposition=decodeURI(res.headers["content-disposition"]);varresult=patt.exec(contentDisposition);变种文件名=结果[1];fileName=fileName.replace(/\"/g,"");//IE兼容方法if(window.navigator&&window.navigator.msSaveOrOpenBlob){window.navigator.msSaveOrOpenBlob(res.data,fileName);return;}constaLink=document.createElement("a");varblob=newBlob([res.data],{type:mimeType});aLink.href=URL.createObjectURL(blob);aLink.setAttribute("下载",fileName);//设置下载文件名document.body.appendChild(aLink);aLink.click();