导出按钮
<el-button
:loading="downloadLoading"
class="left_three"
type="warning"
icon="el-icon-download"
@click="download"
>导出</el-button>
方法
// 导出
download() {
// this.beforeInit();
this.downloadLoading = true;
download().then(res => {
downloadFile(res.data, "空军活动列表", "xlsx");
this.downloadLoading = false;
});
}
通用方法
export function downloadFile(obj, name, suffix) {
const url = window.URL.createObjectURL(new Blob([obj]));
const link = document.createElement("a");
link.style.display = "none";
link.href = url;
const fileName = parseTime(new Date()) + "-" + name + "." + suffix;
link.setAttribute("download", fileName);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
API路由
export const getList = params_list => {
return request({
url: "/api/blade-flight/xxx/list",
method: "post",
params: params_list
});
};