需要注意跨域问题
const onOk = () => {
if (fileUrl.endsWith('pdf')) {
axios({
url: fileUrl,
method: 'get',
responseType: 'blob',
headers: {
'Content-Type': 'application/json;application/octet-stream',
'Cache-Control': 'no-cache'
}
}).then((response) => {
// eslint-disable-next-line no-undef
let fileName = fileUrl.split('/').pop();
let blob = new Blob([response.data]);
let downloadElement = document.createElement('a');
let href = window.URL.createObjectURL(blob);
downloadElement.href = href;
downloadElement.download = fileName;
document.body.appendChild(downloadElement);
downloadElement.click();
window.URL.revokeObjectURL(href);
document.body.removeChild(downloadElement);
}).catch(function (error) {
openNotification('warning', '提示', '下载失败', 'topRight');
});
} else {
window.open(fileUrl);
}
};