vue&react项目中生成下载excel文档
const download = async function (response, fileName) {
const file = await response.arrayBuffer();
let blob = new Blob([file], { type: 'application/vnd.ms-excel;charset=utf-8' })
if (!blob.size) {
return false;
}
const url = window.URL.createObjectURL(blob);
const downloadElement = document.createElement('a');
downloadElement.href = url;
downloadElement.download = fileName || 'download.xls';
downloadElement.target = '_blank';
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
window.URL.revokeObjectURL(url);
return true;
}