React Excel表格导出传参问题
2021-10-11 本文已影响0人
coderhzc
第一种方法(不带文件名称的导出):
今天遇到一个Excel 表格导出传参问题
筛选之后得到的数据,这是就要传参数了
exportPlanData() {
const eventTypeData = this.state.incidentValue ? this.state.incidentValue : ""
const nameData = this.state.shipNameValue ? this.state.shipNameValue : ""
window.location.href = "http://10.100.0.123/api/data/emergencyPlan/export?eventType=" + eventTypeData + "&name=" + nameData
}
实际截图:
image.png第二种方法(导出带文件名称的):
exportPlanData() {
axios({
url: BaseURL + "/data/emergencyPlan/export",
params: {
eventType: this.state.incidentValue ? this.state.incidentValue : "",
name: this.state.shipNameValue ? this.state.shipNameValue : ""
},
responseType: "blob"
}).then(res => {
let fileName = "应急资源.xlsx";
let blob = new Blob([res.data]);
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
link.click(); //点击下载
window.URL.revokeObjectURL(link.href);
link.remove();
}).catch(error => {
message.error("导出失败")
})
}