随笔 - 315  文章 - 1  评论 - 12  阅读 - 24万

vue下载pdf文件

复制代码
async exportCode(){
      await exportEquipmentBarCodePdf({
        equipmentCodes: this.equipmentCodes
      }).then(async (data)=>{
          let a = document.createElement('a'),res=''
          res = data;
          fetch(res.message).then(res => res.blob()).then(blob => { // 将链接地址res.message字符内容转变成blob地址
            a.href = URL.createObjectURL(blob)
            a.download = '巡检设备二维码' // 下载文件的名字
            document.body.appendChild(a)
            a.click()
          })
          // 文件流方式
          /* const isBlob = blobValidate(data);
          if (isBlob) {
            const blob = new Blob([data])
            saveAs(blob, '巡检设备二维码.pdf')
          } else {
            const resText = await data.text();
            const rspObj = JSON.parse(resText);
            const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
            this.$modal.msg(errMsg);
          }*/
      }).catch((r) => {
          this.$modal.msg('下载文件出现错误,请联系管理员!')
      });
    },
复制代码

 

posted on   小虾米吖~  阅读(280)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
历史上的今天:
2018-10-17 jQuery 常用的方法

点击右上角即可分享
微信分享提示