下载压缩文件

117 阅读1分钟

responseType:"blob"     一定要写着括号里!!!!!!!

//下载压缩文件
 upDown(row){
  let param = {
    identification: row.identification,
    projectId: this.itemId
  }
  this.$http.get("/api/xxxx/xxxxx", {
      params:param,
      responseType:"blob"} // 就是这步,也不知道网上那些瞎写的是怎么运行起来的
   ).then(async response => {
      let fileName = '压缩文件.zip';
      const blob = new Blob([response.data], { type: 'application/octet-stream' })
      const url = window.URL.createObjectURL(blob)
      const link = document.createElement('a') // 创建a标签
      link.href = url
      link.download = fileName // 文件重命名,若无需重命名,将该行删去
      link.click()
      URL.revokeObjectURL(url) // 释放内存
    });
},
```
```