let self = this;
self.$axios({
url: URL地址,
type: "get",
responseType: "blob"
})
.then(res => {
if (!res) {
this.$message.error("下载失败");
return;
} else {
if (!!window.ActiveXObject || "ActiveXObject" in window) {
var filename = " NAME " + new Date().toLocaleDateString() + ".xlsx";
var type = "text/plain; charset=UTF-8";
var obj = res.data;
var blob =
typeof File === "function"
? new File([obj], filename, { type: type })
: new Blob([obj], { type: type });
if (typeof window.navigator.msSaveBlob !== "undefined") {
window.navigator.msSaveBlob(blob, filename);
} else {
var URL = window.URL || window.webkitURL;
var downloadUrl = URL.createObjectURL(blob);
if (filename) {
var a = document.createElement("a");
if (typeof a.download === "undefined") {
window.location = downloadUrl;
} else {
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
}
} else {
window.location = downloadUrl;
}
}
} else {
let url = window.URL.createObjectURL(res.data);
let link = document.createElement("a");
link.style.display = "none";
link.href = url;
var filename = " NAME " + new Date().toLocaleDateString() + ".xlsx";
link.setAttribute("download", filename);
document.body.appendChild(link);
link.click();
}
self.fullscreenLoading = false;
}
})
.catch(error => {
console.log(error);
});
网友评论