src/utils/download.js
import axios from "axios";
import { ElMessage } from "element-plus";
import { baseURL1 as baseURL } from "./axios.js";
export function download({ url, params = {} }) {
axios.get(baseURL + url, { params }).then(res => {
if (res.data.code === 0) {
ElMessage.error({
message: res.data.data,
type: "error"
});
} else {
let url = window.URL.createObjectURL(new Blob([res.data]));
let link = document.createElement("a");
link.href = url;
link.setAttribute("download", res.headers.filename);
link.click();
}
});
}
export function hrefDownload(url) {
const a = document.createElement("a");
a.setAttribute("href", url);
a.click();
}
网友评论