请求接口
async exportFn() {
await api.xxxx({})
.then(res => {
let blob = new Blob([res.file], { type: res.file.type })
downloadFileByBlob(blob, `文件-${moment().format('YYYYMMDD')}.xlsx`)
message.success('导出成功')
}).catch(err => err)
},
下载方法
downloadFileByBlob(blob, fileName = "file") {
let blobUrl = window.URL.createObjectURL(blob)
let link = document.createElement('a')
link.download = fileName || 'defaultName'
link.style.display = 'none'
link.href = blobUrl
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
downloadFileByBlob(res.data, '活动策略数据表.xlsx')