纯前端通过文件全路径下载文件并支持重命名
let result = request({ url: file.url, //文件全路径 method: 'get', params: {responseType: 'blob'} }) result.then(response => { let url = window.URL.createObjectURL(new Blob([response])); let link = document.createElement("a"); link.style.display = "none"; link.href = url; link.download = file.name; //文件名称 document.body.appendChild(link); link.click(); document.body.removeChild(link); });
参考:https://www.yuque.com/smallwhy/yyvuqy/tso0in