提交 ea46ed0f authored 作者: zax's avatar zax

文件管理图片下载

上级 858a5137
......@@ -136,13 +136,28 @@ export default {
// 文件下载
download (val) {
if (val.path) {
let link = document.createElement('a');
link.href = val.path;
link.download = val.name;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
let img = /.(png|jpg|jpeg|gif)$/g;
if (img.test(val.path)) { // 图片下载
let x = new XMLHttpRequest();
x.open('GET', val.path, true);
x.responseType = 'blob';
x.onload = (e) =>{
let url = window.URL.createObjectURL(x.response)
let a = document.createElement('a');
a.href = url
a.download = val.name
a.click()
}
x.send();
} else { // 普通文件下载
let link = document.createElement('a');
link.href = val.path;
link.download = val.name;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
} else {
this.$message('没有文件可以下载');
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论