第一种
- 请求api中的response类型必须添加
responseType: "blob"
(因为response回传不存在blob类型,默认字符串,会导致下载的文件无法解析)
exportJournalLogin(params) {
return http({
url: `Journal/Login/Export`,
method: 'POST',
data: params,
responseType: 'blob'
})
},
const blob = new Blob([res]);
const downloadElement = document.createElement("a");
const href = window.URL.createObjectURL(blob);
downloadElement.href = href;
downloadElement.download = `XX文档计算书.docx`;
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
window.URL.revokeObjectURL(href);
download(){
fetch(url).then(res => res.blob()).then(blob => {
const downloadElement = document.createElement('a');
downloadElement.href = URL.createObjectURL(blob)
downloadElement.download = "小明.pdf";
document.body.appendChild(link)
link.click()
window.URL.revokeObjectURL(downloadElement.href);
document.body.removeChild(downloadElement);
});
}
第二种
let url = window.URL.createObjectURL(new window.Blob([res]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', `${this.currentRobot.name}-版本流程数据.xls`)
document.body.appendChild(link)
link.click()
link.parentNode.removeChild(link)
第三种(和第一种差不多)
downloadBlob(res, item, docFormat) {
const endFormat = docFormat || 'mp3'
let link = document.createElement('a')
link.style.display = 'none'
link.href = window.URL.createObjectURL(res)
link.download = this.$route.query.bookName + '-' + item.chapterName + '.' + endFormat
document.body.appendChild(link)
link.click()
URL.revokeObjectURL(link.href)
document.body.removeChild(link)
},
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本