能下载 但无法修改文件名称
var a = document.createElement("a");
a.href = res.url;
a.download = "优惠券记录.xlsx";
a.click();
修改代码
async downloadClick(url, name) {
window.URL = window.URL || window.webkitURL;
var xhr = new XMLHttpRequest();
var a = document.createElement("a");
var file;
xhr.open("GET", url, true);
xhr.responseType = "blob";
xhr.onload = function() {
file = new Blob([xhr.response], { type: "application/octet-stream" });
a.href = window.URL.createObjectURL(file);
a.download = name;
a.click();
};
xhr.send();
}
完美解决
有更好方式 欢迎留言交流哦~