vue blob流下載zip文件


需求是這樣的......

具體實現,前端拿到后端返回回來的數據,然后通過Blob實現下載,文件內容樣式啥的都是后端寫

 
復制代碼
this.axios({
url: baseUrl + '/mails/downloadZipFile',
method: 'GET',
responseType: 'arraybuffer',
params: {
strMailId: this.parm['strMailId']
}
}).then((res) => {
const content = res.data
const blob = new Blob([content], {type: "application/zip"})
var timestamp = (new Date()).valueOf();
const fileName = timestamp + '.zip'
if ('download' in document.createElement('a')) { // 非IE下載
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = window.URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
window.URL.revokeObjectURL(elink.href) // 釋放URL 對象
document.body.removeChild(elink)
} else { // IE10+下載
navigator.msSaveBlob(blob, fileName)
}
}).catch((err) => {
console.log(err);
})
復制代碼

轉載文章:https://blog.csdn.net/Thekingyu/article/details/103140848


免責聲明!

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



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