以文件方式返回:
请求属性:responseType: 'blob'
示例代码:
request.post('/demo/download', {
params: {
fileName: 'aaa'
},
responseType: 'blob'
}).then(res => {
if (res) {
let blob = new Blob([res], { type: 'application/vnd.ms-excel' })
const link = document.createElement("a")
link.href = window.URL.createObjectURL(blob)
link.download = '模版.xlsx'
// fix Firefox
link.style.display = "none"
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(link.href)
} else {
notification.error({
message: '下载模版失败'
})
}
})