
获得徽章 0
- 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('已下载!');
}
```展开赞过评论2 - 有一点 Vue3 的 Hooks 比 React 的 Hooks 好用一千倍,React 的 Hooks 各种心智负担, Vue3 的 Hooks 无脑用就是了,没有任何心智负担。我是 React 入门的前端,后面也有使用 Vue,在 Vue2 时代,确实比较限制高级前端的发挥,因为都限制死了,这也是为啥高级前端都偏爱 React 的原因了。但 Vue3 的用法更偏向 React 了,而且比 React 更灵活了,但从一个公司角度来说,要从 React 技术栈切换到 Vue3 收益并不大,甚至没什么收益。只能说 Vue3 跟 React 差不多了,单从用法上来说,某些方法甚至比 React 更好,但从公司角度来说,不可能因为这点收益就切换技术栈。展开等人赞过评论6