JS下载:
```
// 请求需要加 responseType: 'blob'
request.get(
`/iop/marketing/common/downloadFile?fileId=${fileId}&fileName=${fileName}`,
{ responseType: 'blob' }
)


const downloadEvtHandle = (item: any) => {
fetchDownloadFile(item.fileId, item.fileName).then((r: any) => {

r = r || {}
const blob = new Blob([r], { type: 'text/plain' })
const url = window.URL.createObjectURL(blob);
openUrl(url, item.fileName)

}).catch(err => console.error(err))
}

/**
* 打开附件下载
* @param {*} url
* @param {*} name
*/
const openUrl = (url: string, name: string) => {
const a = document.createElement('a');
a.setAttribute('href', url);
a.setAttribute('target', '_blank');
a.setAttribute('download', name);
a.click();
Message.success('已下载!');
}
```
展开
评论