浏览器会默认打开图片/pdf/txt文件,可通过以下方法将url转为文件流再保存本地
fetch(url, {
responseType: 'blob'
}).then(res => {
const url = window.URL.createObjectURL(new Blob([res.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', name);
link.click();
});