vue接受后台文件流进行打印

请求类型 responseType: "blob",
axios({
          methods: "get",
          url: url,
          params: {
            contractId: this.contractId,
          },
          responseType: "blob",
        }).then((res) => {
          const content = res.data;
          this.pdfUrl = window.URL.createObjectURL(
            new Blob([content], { type: "application/pdf" })
          );
          // window.open(this.pdfUrl);
          var date = new Date().getTime();
          var ifr = document.createElement("iframe");
          ifr.style.frameborder = "no";
          ifr.style.display = "none";
          ifr.style.pageBreakBefore = "always";
          ifr.setAttribute("id", "printPdf" + date);
          ifr.setAttribute("name", "printPdf" + date);
          ifr.src = this.pdfUrl;
          document.body.appendChild(ifr);
          this.doPrint("printPdf" + date);
          window.URL.revokeObjectURL(ifr.src); // 释放URL 对象
        });
//打印
    doPrint(val) {
      var ordonnance = document.getElementById(val).contentWindow;
      setTimeout(() => {
        ordonnance.print();
        this.pdfLoading = false;
      }, 100);
    },
posted @   seekHelp  阅读(1193)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
历史上的今天:
2020-08-31 react中map的应用
2020-08-31 react组件的应用
2020-08-31 react的基础用法(1)
点击右上角即可分享
微信分享提示