美文网首页
处理后端返回的pdf的文件流后预览

处理后端返回的pdf的文件流后预览

作者: PharkiLL | 来源:发表于2020-12-16 15:33 被阅读0次
// 需要安装 vue-pdf插件
 import pdf from 'vue-pdf';
 // pdf 预览
getPdfUrl() {
        if(this.formData.businessTicketFrontPath) {
          getImgUrl(this.formData.businessTicketFrontPath).then(res=>{
            console.log('res:',res);
            this.pdfVisible = true;
            const {data, header} = res
            const blob = new Blob([data])
            let url = window.URL.createObjectURL(blob)
            this.getNumPages(url)
          })
        }
      },
getNumPages(pdfUrl) {
        var loadingTask = pdf.createLoadingTask(pdfUrl)
        loadingTask.promise.then(pdf => {
          this.pdfUrl = loadingTask
          this.numPages = pdf.numPages
        }).catch((err) => {
          console.error('pdf加载失败')
        })
 },

相关文章

网友评论

      本文标题:处理后端返回的pdf的文件流后预览

      本文链接:https://www.haomeiwen.com/subject/ceongktx.html