注意加 responseType:'arraybuffer'
注意加 responseType
axios({
method: 'post',
url: '/api/data/weapon/exportExcel',
data: params,
params: {
isXlsx: false
},
responseType:'arraybuffer',
headers: {
accept: '*/*',
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip, deflate'
}
}).then((res: any) => {
console.log(res)
var blob = new Blob([res.data], { type: 'application/vnd.ms-excel;charset=utf-8;' });
// FileReader主要用于将文件内容读入内存
let a = document.createElement('a');
a.href = window.URL.createObjectURL(blob);
a.download = '武器库.xlsx';
a.click(); // 模拟点击a标签
window.URL.revokeObjectURL(a.href);
setLoading(false)
})
网友评论