下载图片:
async handlePreview(file) {
if (window.navigator.msSaveOrOpenBlob) {
await 后台接口(参数).then((res) => {
// 兼容IE
const blob = new Blob([res.data], { type: "application/png" });
navigator.msSaveBlob(blob, "图片");
});
} else {
// 这里就按照chrome等新版浏览器来处理
var a = document.createElement("a");
var event = new MouseEvent("click");
a.download = "图片";
a.href = file.url;
a.dispatchEvent(event);
}
},
下载zip压缩包文件:
Down() {
后台接口()
.then((res) => {
let blob = new Blob([res.data], { type: "application/zip" });
if (window.navigator.msSaveOrOpenBlob) {
// 兼容IE
navigator.msSaveBlob(blob);
} else {
let url = window.URL.createObjectURL(blob);
const link = document.createElement("a"); // 创建a标签
link.href = url;
link.download = ""; // 重命名文件
link.click();
URL.revokeObjectURL(url); // 释放内存
}
})
.catch((res) => {
});
},
查看pdf和图片:
await 接口(参数).then((res) => {
const blob = new Blob([res.data], { type: "application/pdf" });
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob);
getURL = "";
} else {
getURL = window.URL.createObjectURL(blob);
}
});
case ext == "pdfx" || ext == "pdf":
if (getURL != "") {
window.open(getURL, "_blank");
}
break;