axios({
method: 'post',
url: obcsPath + 'file/download.do',
responseType: 'blob',
headers: { 'Content-Type': 'application/json; application/octet-stream' },
}).then((res) => {
// let blob = new Blob([res.data], { type: 'application/octet-stream' })
// const downloadUrl = window.URL.createObjectURL(blob)
// const link = document.createElement('a')caa
// link.href = downloadUrl
// link.setAttribute('download', 'dayin.zip') //any other extension
// document.body.appendChild(link)
// link.click()
// document.body.removeChild(link) //下载完成移除元素
// window.URL.revokeObjectURL(downloadUrl) //释放blob对象
if ('msSaveOrOpenBlob' in navigator) {
//ie
var data = res.data
var blob = new Blob([data], { type: 'application/octet-stream' })
window.navigator.msSaveOrOpenBlob(blob, 'mb.zip')
return
} else {
const url = window.URL.createObjectURL(new Blob([res.data]))
const link = document.createElement('a')
let fname = '文件上传模板.zip'
link.href = url
link.setAttribute('download', fname)
document.body.appendChild(link)
link.click()
}
})
前端文件下载zip包(万能包)
最新推荐文章于 2024-06-07 15:29:04 发布