// vue中使用A标签下载附件
<span @click="clickDown()">下载模板</span>
clickDown() {
let urlIt = "/api/exportMaterialModuleFile"; //下载接口
this.axios({
method: "get",
url: this.domainName + urlIt, //this.domainName 是域名 比如:http://192.168.2.160:8080
responseType: "blob",
}).then(function (res) {
if (!res.data) {
return;
}
var name = "物料信息模板.xlsx"; //附件命名需加后缀,否则就是走默认后缀 .txt
var blob = new Blob([res.data]);
var url = window.URL.createObjectURL(blob);
var aLink = document.createElement("a");
aLink.style.display = "none";
// aLink.href = res.config.url; 使用这个路径,会出现请求头不带token
aLink.href = url;
aLink.setAttribute("download", name);
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink); //下载完成移除元素
window.URL.revokeObjectURL(url); //释放掉blob对象
});
}