要对返回的数据进行文件流解析文件流将会被转成blob对象
async handleDownLoad(file) {
axios
.request({
url: '接口地址',
method: 'get',
responseType: 'blob', //文件流将会被转成blob对象
params //接口参数
})
.then(res => {
if (res.data) {
let blob = new Blob([res.data])
let url = window.URL.createObjectURL(blob)
let aLink = document.createElement('a')
aLink.style.display = 'none'
aLink.href = url
aLink.setAttribute('download', file.name)
document.body.appendChild(aLink)
aLink.click()
document.body.removeChild(aLink)
window.URL.revokeObjectURL(url)
} else {
this.$message({ type: 'error', message: '获取下载文件失败' })
}
})
}