js使用a标签下载文件并指定名称
当使用js下载路径带有xxxxx.png 的路径图片时,下载下来的名称一直是xxxxx.png,有时候又需要指定文件名称,代码如下
downFile(ShowUrl,Name) { // ShowUrl 表示路径 Name 表示需要的名称
const x = new window.XMLHttpRequest();
x.open('GET', ShowUrl, true);
x.responseType = 'blob';
x.onload = () => {
const url = window.URL.createObjectURL(x.response);
const a = document.createElement('a');
a.href = url;
a.target = '_blank'
a.download = Name;
a.style.display = 'none'
document.body.append(a)
a.click();
};
x.send();
},

浙公网安备 33010602011771号