vue前端下载流文件不正常的解决方法

 this.$http
        .post(
          "report/download",
          {
            name: this.name,
            html: imageWrapper.innerHTML,
          },
          {
            headers: {
              "Content-Type": "application/json;charset=utf-8",
              //"Content-Type": "application/x-www-form-urlencoded",
            },
            responseType: "blob", //关键
          }
        )
        .then((res) => {
          const pdfUrl = window.URL.createObjectURL(
            new Blob([res.data], { type: `application/pdf` })
          );

          const link = document.createElement("a");
          link.href = pdfUrl;
          link.setAttribute("download", this.name);
          document.body.appendChild(link);
          link.click();
          link.remove(); // 一次性的,用完就删除a标签
        });

  

posted @ 2022-05-11 14:24  贾平凡  阅读(705)  评论(0)    收藏  举报