vue 点击事件 点击下载文件
// 点击下载文件downloadFile(item) {this.contextFile.index = -1;item.path = item.path.replace(/^http:/,"https:");this.download(item.path, item.title);},download (src,...
·
// 点击下载文件
downloadFile(item) {
this.contextFile.index = -1;
item.path = item.path.replace(/^http:/,"https:");
this.download(item.path, item.title);
},
download (src, fileName) {
let x = new XMLHttpRequest();
x.open("GET", src, true);
x.responseType = 'blob';
x.onload = function(e) {
let url = window.URL.createObjectURL(x.response)
let a = document.createElement('a');
a.href = url
a.download = fileName
a.click()
}
x.send();
},
更多推荐
已为社区贡献50条内容
所有评论(0)