const blob = new Blob([res], { type: 'application/octet-stream' }) //res为后台返回的文件流,注意参数是以数组的形式上传
const href = URL.createObjectURL(blob) //URL都要大写,这点也要注意
const link = document.createElement('a') //生成a标签用于模拟下载
link.download = `销售订单.xls` //自定义下载文件名称
link.href = href //把生成的href赋值到a标签上,在这里我遇到一个问题,
//直接赋值无法把href赋值到a标签的href上(不知道是不是因为封装框架的问题)
//我采用了原生的方法
//link.setAttribute("href", href);
document.body.appendChild(link)
link.click()
//释放空间
document.body.removeChild('link')
URL.removeObjectURL(href)
在接口里加入 responseType: 'blob'
//导出
export function exportXls(query) {
return axios({
url: '/xfSellOrder/exportXls',
method: 'get',
params: query,
responseType: 'blob'
})
}