json文件链接用window.open(url);会显示在浏览器上,并不保存到本地。所以,需要调整下载策略。

function download(){

let url='https://resource.ilocalize.net.cn/%E6%96%87%E4%BB%B6-1-0a983272211a4d14b847eaf034492f30.json';
//window.open(url);

downloadUrlFile(url, '测试文件.json');
}

// 下载含有url的文件
function downloadUrlFile(url, fileName) {
const url2 = url.replace(/\\/g, '/');
const xhr = new XMLHttpRequest();
xhr.open('GET', url2, true);
xhr.responseType = 'blob';
//xhr.setRequestHeader('Authorization', 'Basic a2VybWl0Omtlcm1pdA==');
// 为了避免大文件影响用户体验,建议加loading
xhr.onload = () => {
if (xhr.status === 200) {
// 获取文件blob数据并保存
saveAs(xhr.response, fileName);
}
};
xhr.send();
}

function saveAs(data, name) {
const urlObject = window.URL || window.webkitURL || window;
const export_blob = new Blob([data]);
//createElementNS() 方法可创建带有指定命名空间的元素节点。
//此方法可返回一个 Element 对象。
const save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
save_link.href = urlObject.createObjectURL(export_blob);
save_link.download = name;
save_link.click();
}