Vue3中如何点击按钮下载网络文件?这个功能很简单,一个函数就能搞定。下面直接上代码:
const download = (row: any) => {
// 获取文件名及扩展名
const fileName = row.name
let link = document.createElement('a')
link.style.display = 'none'
link.href = row.url
// 设置 download 属性为文件名(包含扩展名)
link.setAttribute('download', fileName)
// 将链接添加到页面并触发点击事件
document.body.appendChild(link)
link.click()
// 点击完成后,移除链接
document.body.removeChild(link)
}
全部评论