关于vue.js:vue下载文件

3次阅读

共计 322 个字符,预计需要花费 1 分钟才能阅读完成。

通过 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()![]
      })
    },

正文完
 0