如果后端给你返回base64格式的excel,用它就对了
this.tableLoading = true
const xmlResquest = new XMLHttpRequest()
const _this = this
xmlResquest.open('POST', api.dealerCuxStockingTask_taskDetailDownload, true) // 接口地址和请求方式
xmlResquest.setRequestHeader('Content-type', 'application/json;charset=UTF-8')
xmlResquest.setRequestHeader('Certificate', this.userInfo.certificate)
xmlResquest.responseType = 'blob'
xmlResquest.onload = function (event) {
if (this.status === 200) {
const link = document.createElement('a')
const blob = new Blob([xmlResquest.response])
link.setAttribute('href', window.URL.createObjectURL(blob))
link.setAttribute('download', `文件名${moment().format('YYYY-MM-DD HH:mm:ss')}.xlsx`)
link.style.display = 'none'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
_this.tableLoading = false
} else {
_this.tableLoading = false
_this.$message.error('下载失败')
}
}
xmlResquest.send(JSON.stringify({
data: {
taskId: _this.$route.query.taskId // 接口传参
},
}))