发送请求
注意: 需要将responseType
设置为blob
export function downLoadExcel(data) {
return request({
url: '/endpoint/export/excel/' ,
method: 'post',
responseType: 'blob',
data
})
}
下载
import { downLoadExcel } from '@/api/common'
export default function(excel) {
downLoadExcel(excel).then(res => {
console.log(res)
downLoadBlob(res)
})
}
const downLoadBlob = response => {
const link = document.createElement('a')
const blob = new Blob([response.data], { type: 'application/x-xls' })
link.style.display = 'none'
link.href = URL.createObjectURL(blob)
link.download = response.headers['content-disposition'].split('fileName=')[1] // 下载后文件名
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}