简体   繁体   中英

Get blank while using vue-pdf

I want to use vue-pdf to preview online pdf file. But I always got blank page and there is no error message on console. My code is

<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 version: 2.9.6 vue-pdf version: 4.0.6

Do not re-assign variable src . Your onmounted function is re-assigning src to something else just change it to:-

  .....
  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
})
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM