<div class="item">
<!-- <div class="operate">
<span @click="handleDownLoad()">[下载]</span>
</div> -->
</div>
handleDownLoad() {
let that = this;
let xhr = new XMLHttpRequest();
xhr.open("GET", this.fileUpdateUrl, true);
// xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.responseType = "blob";
//下载
xhr.onload = function (oEvent) {
if (xhr.readyState === 4 && xhr.status === 200) {
//that.fileUpdateUrl 后端地址
const blob = new Blob([that.fileUpdateUrl]); // 构造一个blob对象来处理数据
const fileName = "xxxx.exe"; // 导出文件名文件名可以自定义后缀(是否带文
件类型,例如:xxx.txt 或者 xxx)
// a.download = url.split('/')[url.split('/').length -1]
const link = document.createElement("a"); // 创建a标签
link.download = fileName; // a标签添加属性
link.style.display = "none";
link.href = URL.createObjectURL(blob);
document.body.appendChild(link);
link.click(); // 执行下载
URL.revokeObjectURL(link.href); // 释放url
document.body.removeChild(link); // 释放标签
}
};
xhr.send();
},