引用 及使用
import pdf from 'vue-pdf'
export default {
name: 'Pdf',
components:{
pdf
},
data(){
return{
src: "",
vuePdf: null,
numPages:1,
}
}
}
html
<pdf :src="src" v-for="i in numPages"
:key="i"
:page="i"></pdf>
js
created(){
this.pdfLoadTask()
},
methods:{
pdfLoadTask () {
this.vuePdf = require('vue-pdf')//为了防止第二次进入空白页
this.src = this.vuePdf.default.createLoadingTask("pdf地址")//放在你的打包同级目录下即可
this.src.promise.then(pdf => {//为了显示全部的页码
this.numPages = pdf.numPages;
})
},
}