axios 或 ajax 请求文件

时间:2023-03-09 10:01:48
axios 或 ajax 请求文件

axios 或 ajax 请求文件

 axios({
url: path + '/monitor/exportPicture' + '?access_token=' + getToken(),
method: 'post',
type: 'application/zip',
data: this.pptFormInfo,
responseType: 'blob'
}).then(response => {
const blob = new Blob([response.data])
const fileName = this.schemeName + '.zip'
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)
this.disable = false
} else { // IE10+下载
navigator.msSaveBlob(blob, fileName)
this.disable = false
}
})