//点击下载公告
downloadResult(item) {
const t = this;
const data = {
realPath: item.filePath,
fileName: item.fileName
};
t.$axios
.get("/api/common/down", {
responseType: "blob",
params: data
})
.then(res => {
this.downloadFile(res.data, data.fileName);
});
},
downloadFile(data, name) {
if (!data) {
this.$message.error("下载失败,解析数据为空!");
return;
}
// 创建一个新的url,此url指向新建的Blob对象
let url = window.URL.createObjectURL(new Blob([data]));
// 创建a标签,并隐藏改a标签
let link = document.createElement("a");
link.style.display = "none";
// a标签的href属性指定下载链接
link.href = url;
//setAttribute() 方法添加指定的属性,并为其赋指定的值。
link.setAttribute("download", name);
document.body.appendChild(link);
link.click();
},
js下载文件
于 2020-04-02 09:28:31 首次发布