vue下载文件
文章目录
通过url下载文件
downloadFile(dfile) {
// dfile是文件地址
fetch(dfile).then(res => res.blob()).then(blob => { // 将链接地址字符内容转变成blob地址
const a = document.createElement('a')
a.href = URL.createObjectURL(blob)
console.log(a.href)
//截取路径中的文件名
a.download = dfile.substring(dfile.lastIndexOf("/")+1,dfile.length ) // 下载文件的名字
document.body.appendChild(a)
a.click()![]
})
},

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论