1、需要再请求添加参数
responseType: 'blob'
export async function exportList (params) {
return request(`/content/export`, {
method: 'GET',
params,
responseType: 'blob'
})
}
2、拿到数据使用a标签进行下载
async exportList () {
const params = {}
const res = await exportList(params)
const blob = new Blob([res], {
type: 'application/vnd.ms-excel'
})
const objectUrl = URL.createObjectURL(blob)
const a = document.createElement('a')
a.setAttribute('href', objectUrl)
a.setAttribute('download', `${new Date().getTime()}.xls`)
a.click()
}