const downFile = (fileName:string)=>{
// 设置响应类型为'blob'以接收二进制数据
axios({
method: 'get',
url: urlIpi + '/common/download',
params:{filename,delete:false}, // URL参数
// responseType: 'blob', // 重要
}).then(response => {
download(fileName);
}).catch(error => {
console.error('下载失败:', error);
});
}
const download=(fileName) => {
let protocol = window.location.protocol
let host = window.location.host
let url = `${protocol}://${host}/${fileName}`;
const a = document.createElement('a')
a.setAttribute('download', fileName )
a.setAttribute('target', '_blank')
a.setAttribute('href', url)
a.click()
}
第二种:
<a id="downFile" href="http://xxxx.xxxx.xxx.xxxx:8081/common/download?fileName=%2F2024%2F05%2F21%2Fmetasec-license_20230521164939A003.docx" download="文件" class="app-margin-right-10">
<i class="abc"></i>
</a>