请求后端接口,拿到file
html
<div>
<el-button type="primary" @click="thetemplate()">execl模板下载</el-button>
</div>
js
thetemplate() {
this.$http({
url: this.$http.adornUrl(
"/terminal/doorLock/poi-lock-empower-download"
),
method: "post",
data: this.$http.adornData({}),
responseType: "blob"
}).then(({ data }) => {
console.log(data);
this.downloadFile(data);
});
},
// 文件下载
downloadFile(data) {
// 文件导出
if (!data) {
return;
}
let url = window.URL.createObjectURL(new Blob([data]));
let link = document.createElement("a");
link.style.display = "none";
link.href = url;
link.setAttribute("download", "门锁导入批量模板.xlsx");
document.body.appendChild(link);
link.click();
},