下载图片,如png,jpg等
installImage() {
img(this.id)
.then((res) => {
const url = URL.createObjectURL(res);
const link = document.createElement("a");
document.body.appendChild(link);
link.download = "图片单张下载"+".png";
link.href = url;
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
})
.catch((error) => {
this.$message({ message: error.message, type: "error" });
});
},
下载zip
atchDownload() {
pictureDown(this.$route.query.idX)
.then((res) => {
const url = URL.createObjectURL(res);
const link = document.createElement("a");
document.body.appendChild(link);
link.download = "图片包" + ".zip";
link.href = url;
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
})
.catch((error) => {
this.$message({ message: error.message, type: "error" });
});
},
注意:这两种在请求的头部都需要发送blob请求
export function imgDownLoad(query) {
return request({
url: `请求地址`,
method: 'get',
responseType: "blob",
params: query
})
}
|