download属性的兼容性
由于文件服务器的地址不同,导致跨域的问题,使得a标签的download="filename"不生效
解决方案:
downloadErrorFile () {
this.getBlob('文件的url').then(blob => {
let a = document.createElement('a');
let url = window.URL.createObjectURL(blob);
a.setAttribute('href', url);
a.setAttribute('target', '_blank');
a.setAttribute('download', '错误数据');
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
});
},
getBlob (url) {
return new Promise(resolve => {
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = () => {
if (xhr.status === 200) {
resolve(xhr.response);
}
};
xhr.send();
});
},