方法一
<Button @click="exportAll" :disabled="listData.length == 0" icon="md-trash" :loading="exportLoading">导出数据</Button>
exportAll() {
//导出excel文件
let downloadUrl = "/api/platform/export_exl?department="+this.excelForm.department+
"&from="+this.excelForm.from+
"&keyword="+this.excelForm.keyword+
"&status="+this.excelForm.status+
"&to="+this.excelForm.to+
"&type="+this.excelForm.type;
let oReq = new XMLHttpRequest();
oReq.open("POST", downloadUrl, true);
oReq.responseType = "blob";
oReq.onload = function () {
var content = oReq.response;
var blob = new Blob([content]);
// 创建a标签,下载处理过的文件流
var elink = document.createElement('a');
elink.download = "excel名.xls";
elink.href = URL.createObjectURL(blob);
elink.click();
};
oReq.send();
},
https://www.jianshu.com/p/689d0cb4cc9c
方法二
<Button type="warning":loading="batchExportLoading" @click="batchExportFile">导出</Button>
batchExportFile(){
if(this.batchList.length == 0){
this.$Message.warning("暂无数据,请查询数据!");
return;
}
this.batchExportLoading = true;
let _this = this;
let downloadUrl = "/api/search/batchExport";
let oReq = new XMLHttpRequest();
oReq.open("POST", downloadUrl, true);
oReq.setRequestHeader("Content-type", "application/json;charset=UTF-8");
oReq.responseType = "blob";
oReq.onload = function () {
_this.batchExportLoading = false;
var content = oReq.response;
var blob = new Blob([content]);
// 创建a标签,下载处理过的文件流
var elink = document.createElement('a');
elink.download = "批量查重结果.xlsx";
elink.href = URL.createObjectURL(blob);
elink.click();
};
//参数
oReq.send(JSON.stringify(this.batchList));
},
方法三
function obj2Query(params) {
let q = '';
for (let key in params) {
if (params[key]) {
q += `&${key}=${params[key]}`;
}
}
return q.slice(1);
}
export const exportlist = (params) => {
let q = obj2Query(params);
window.open(`${downloadAddr}/api/export/exportlist?${q}`)
}