this.$axios
  .post(url接口地址, params请求参数, {
    headers: {
      token: token
    },
    responseType: "arraybuffer"
  })
  .then((file) => {
    let content = file.data;
    // 组装a标签
    let elink = document.createElement("a");
    // 设置下载文件名
    elink.download = "附件.zip";
    elink.style.display = "none";
    let blob = new Blob([content], {type: "application/zip"})
    elink.href = URL.createObjectURL(blob);
    document.body.appendChild(elink);
    elink.click();
    document.body.removeChild(elink);
  })

注意:responseType应设置为:'arraybuffer',这样返回的文件流才会是二进制的,才能使用new Blob得到正确的文件

相关文章:

  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-14
  • 2022-02-16
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案