首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用vue-pdf时为空

在使用vue-pdf时为空
EN

Stack Overflow用户
提问于 2019-05-27 22:04:23
回答 1查看 577关注 0票数 1

我想用vue-pdf来预览在线pdf文件。但我总是得到空白页面,并且控制台上没有错误信息。我的代码是

代码语言:javascript
复制
<template>
<div class="pdf">
  <pdf 
    :src="src">
  </pdf>
</div>
</template>
<script>
import pdf from 'vue-pdf'
export default {
  name: 'Pdf',
  components:{
      pdf
  },
  data(){
      return {
          src:"http://file.dakawengu.com/file/2018-05-29/20180527-tianfeng.pdf",
      }
  },
  mounted() {
    this.src = pdf.createLoadingTask(this.src)
    this.src.then(response => {
      this.numPages = response.numPages
    })
  }
}

</script>

vue版本: 2.9.6 vue-pdf版本: 4.0.6

EN

回答 1

Stack Overflow用户

发布于 2021-04-17 04:09:59

不要重新分配变量src。您的挂载函数正在将src重新分配给其他对象,只需将其更改为:-

代码语言:javascript
复制
  .....
  data(){
  return {
      src:"http://file.dakawengu.com/file/2018-05-29/20180527-tianfeng.pdf",
      newsrc: null,
  }
 },
 .................
 ........your code..............
 ........................
mounted() {
  this.newsrc = pdf.createLoadingTask(this.src)
  this.newsrc.then(response => {
    this.numPages = response.numPages
})
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56327618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档