javascript
// pdf、xlsx或其他文件无预览下载
const url = '你的文件url链接'
let fileName = url.substring(url.lastIndexOf('/') + 1)
console.log("fileName--",fileName)
let isPdf = url.endsWith('.pdf')
const request = new XMLHttpRequest();
request.responseType = 'blob';
request.open('GET', res.data.url);
request.onload = function () {
const link = document.createElement('a');
document.body.appendChild(link);
this.response.arrayBuffer().then(buf => {
const blob = new Blob([buf]);
const url = URL.createObjectURL(blob);
link.style.display = 'none';
link.target = '_blank';
link.download = fileName;
link.href = url;
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
});
};
request.send();