//导出excel记录
const exportExcel = async () => {
//请求后台导出excel数据
try {
var oReq = new XMLHttpRequest();
var url = '/url';
var title = '**数据';
oReq.open('GET', url, true);
oReq.responseType = 'blob';
oReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
oReq.onload = (oEvent) => {
var content = oReq.response;
var elink = document.createElement('a');
elink.download = title + '记录表.xlsx';//xlsx 因为后台输入是scv格式,用xlsx显示的不理想
elink.style.display = 'none';
var blob = new Blob([content]);
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
document.body.removeChild(elink);
};
oReq.send();
} catch (error) {
message.error('导出excel记录出现异常'!)
}
}
|