浏览了很多资料,这个其实是vue-pdf的bug,也看一个博主推荐git上大家讨论的 issues!但是没有实质性的解决方案!

后面尝试了来个偷天换日,给个定时器解决了!

showPdf(item) {
       // 因为可以点击在一个页面点击可选择多个pdf进行查看,所以每次调接口前先给pdf页面置空
      this.currentNum = null
      this.pageNum = null
      const params = {
        fileName: item
      }
      downloadPdfFile(params).then(res => {
        this.pdfUrl = window.URL.createObjectURL(res)
        const loadingTask = PDF.createLoadingTask(this.pdfUrl, CMapReaderFactory)
        loadingTask.promise
          .then((pdf) => {
            this.pageNum = pdf.numPages
            this.showPop = true
            // 用个定时器解决报错Rendering cancelled
            var timer = setInterval(() => {
              this.currentNum += 1
              if (this.currentNum === this.pageNum) {
                clearInterval(timer)
              }
            }, 500)
          })
          .catch(err => {
            console.error('pdf 加载失败', err)
          })
      })
    }

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐