请求后端导出表格数据的时候需要对后端返回的数据进行下载
导出表格需要在请求添加
responseType: 'blob',
export function blobFun(res) {
let blob = new Blob([res]);
let downloadFilename = 'form' + ".xlsx";
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, downloadFilename);
} else {
let url = window.URL.createObjectURL(blob);
let downloadElement = document.createElement("a");
downloadElement.style.display = "none";
downloadElement.href = url;
downloadElement.download = downloadFilename;
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
window.URL.revokeObjectURL(url);
}
}
|