一般来说,咱们有一个下载链接 url,window.open(url, “_blank”) 就能够实现下载,然而这个有个问题就是文件默认的名称兴许不是需要心愿的,然而咱们又心愿能够指定一个名称,就能够采纳上面的方法
onDownload(url,fileName) {
let self = this;
let x = new XMLHttpRequest();
x.open("GET", url, true);
x.responseType = "blob";
x.onload = function() {
//self.exportLoading = false;
let url = window.URL.createObjectURL(x.response);
let a = document.createElement("a");
a.href = url;
a.download = fileName;
a.click();};
x.send();},