1.导出按钮
<el-form-item>
<el-button @click="downloadExcel()" type="primary">导出</el-button>
</el-form-item>
2.调用接口
// 导出
downloadExcel() {
this.exportBalanceOrder()
},
async exportBalanceOrder(){
let queryParams = this.queryParams;
//调用接口
await this.$api.tradeMgmt.exportOrderForm(queryParams).then((res) => {
this.downloadCallback(res, '藏品交易记录.xls');
});
},
//生成下载文件
downloadCallback(res, fileName){
const content = res.data;
const blob = new Blob([content]);
if ("download" in document.createElement("a")) {
// 非IE下载
const elink = document.createElement("a");
elink.download = fileName;
elink.style.display = "none";
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
} else {
// IE10+下载
navigator.msSaveBlob(blob, fileName);
}
},
3.封接口
//藏品交易记录导出
exportOrderForm(params) {
return axios.post(`/backstageOrder/exportOrderForm`, qs.stringify(params),{ responseType: "blob" });
},
重点:接口里面一定要写 responseType: "blob"