post 请求文件流
axios.post('/url/xxx',{},{responseType: 'blob' })
.then(res => {
const elink = document.createElement('a');
elink.download = 'xxx1.xlsx';
elink.style.display = 'none';
const blob = new Blob([res], { type: 'application/vnd.ms-excel' });
const href = URL.createObjectURL(blob);
elink.href = href;
document.body.appendChild(elink);
elink.click();
document.body.removeChild(elink);
window.URL.revokeObjectURL(href);
})
.catch(err => {
throw new Error(err);
});
get 请求文件流
axios.get('/url/xxx', { params, responseType: 'blob' })
axios post请求下载文件流
于 2022-03-17 12:12:47 首次发布