- export function downloadFile(url: string) {
- // 创建隐藏的 <a> 标签
- const link = document.createElement('a')
- link.href = url
- link.style.display = 'none'
- // 设置 download 属性(即使跨域,部分浏览器仍会尝试下载)
- link.download = url.split('/').pop() || 'file' // 自动提取文件名
- document.body.appendChild(link)
- link.click()
- document.body.removeChild(link)
- }
|