axios.post(url
, fd
, {
headers: {
'Content-Type': 'multipart/form-data'
},
responseType: 'blob'
}
).then(res=>{
const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' })
const date = new Date()
const url = window.URL.createObjectURL(blob)// 为文件流创建构建下载链接
const link = document.createElement('a')// 创建a标签
link.style.display = 'none'
link.href = url
link.setAttribute('download', `名称-${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}.xls`)// 设置a标签的下载动作和下载文件名
document.body.appendChild(link)
link.click()// 执行下载
document.body.removeChild(link)// 释放标签
})
网友评论