vue文件下载
请求为get

请求为post
this.$http 自己创建的axios请求
let BASE_URL = this.$http.BASE_URL
const downLoadRequest = this.$http.create({
baseURL: BASE_URL,
headers: {
'Content-Type': 'application/json; charset=utf-8',
'token': this.$cookie.get('token')
}
})
downLoadRequest({
url: '/at/atreceiveprizerecord/export',
method: 'post',
data: {
'drawRecordIds': drawRecordIds,
'redeemRecordIds': redeemRecordIds,
'activityName': this.searchForm.activityName,
'username': this.searchForm.username,
'drawResult': this.searchForm.drawResult,
'isCash': this.searchForm.isCash,
'prizeName': this.searchForm.prizeName,
'type': type,
'prizeStatus': this.searchForm.prizeStatus
},
responseType: 'blob'
}).then((res) => {
console.log(res.data)
let fileName = new Date().getTime() + '.xls'
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(res.data, fileName)
} else {
let link = document.createElement('a')
link.href = window.URL.createObjectURL(res.data)
link.download = fileName
link.click()
// 释放内存
window.URL.revokeObjectURL(link.href)
}
}).catch((e) => {
this.$message.error('文件下载失败,请联系管理员!!!')
})
浙公网安备 33010602011771号