post请求导出Excel表格

纵饮孤独 提交于 2020-05-04 03:44:57
axios. interceptors. response. use(( response) =>{
if( response. config && response. config. responseType == 'blob') {
const blob = new Blob([ response. data], { type: 'application/x-msdownload' }); //后台需要相同的type
let filename = ` ${ name } .xls`;
if ( 'download' in document. createElement( 'a')) {
const downloadElement = document. createElement( 'a');
let href = '';
if( window. URL) href = window. URL. createObjectURL( blob);
else href = window. webkitURL. createObjectURL( blob);
downloadElement. href = href;
downloadElement. download = filename;
document. body. appendChild( downloadElement);
downloadElement. click();
if( window. URL) window. URL. revokeObjectURL( href);
else window. webkitURL. revokeObjectURL( href);
document. body. removeChild( downloadElement);
} else {
navigator. msSaveBlob( blob, filename);
}
return Promise. resolve( response. data);
}
return response;
})
const defaultConfig = {
baseURL: '',
mode: 'cors',
headers: {
// "your-content": 'application/x-msdownload',
"Accept" : "application/json",
"Content-Type" : "application/json;charset=utf-8"
},
responseType: 'json'
}
const post2 = ( url, data, config) => {
return axios. post( url, data, Object. assign({}, defaultConfig, config))
}
https. post2( this. apiName. exportMealGroupByDateAndShop, data,{ responseType: 'blob' })

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!