后端返回加密的url 可以直接使用 " window.location.href = url " 进行下载,不能进行重命名,
需要重命名时调用以下方法 传 : url , 需要重命名的文件名称
downloadFile(url, fileName) {
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = function() {
if (xhr.status === 200) {
const blob = new Blob([xhr.response]);
const a = document.createElement('a');
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
}
};
xhr.send();
},