js post下載文件 后端返回文件流


// 導出excel
handleExport = () => {
const data = { ...this.state };
data.keyword = this.keyword;
Post({ url: "/projectInfo/exportProjectInfoList", data: data, type: "upload", responseType: "blob" }).then(res => {
if (res.size != 88) {
const content = res
const blob = new Blob([content])
const fileName = '項目信息表.xls'
if ('download' in document.createElement('a')) { // 非IE下載
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 釋放URL 對象
document.body.removeChild(elink)
} else {
navigator.msSaveBlob(blob, fileName)
}
} else {
message.error("該賬號無導出項目權限", 0.5)
}

})
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM