在浏览器url输入该地址 会出现文件
async downLoad(mapUrl) {
console.log('执行了几次',mapUrl);
let that=this
var url = mapUrl;
var xhr = new XMLHttpRequest();
xhr.open("GET", url); // 异步
xhr.responseType = "blob"; // blob 类型
xhr.send();
xhr.onload = await function() {
if (xhr.status != 200) {
return;
}
if (window.navigator.msSaveOrOpenBlob) {
// IE
// navigator.msSaveBlob(xhr.response, filename);
// navigator.msSaveBlob(xhr.response, filename);
} else {
// mapFileName
var newUrl = window.URL.createObjectURL(xhr.response);
var a = document.createElement("a");
a.setAttribute("href", newUrl);
a.setAttribute("target", "_blank");
a.setAttribute("download", that.faceForm.mapFileName); // 自定义文件名(有效)
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
};
}