我想用vue-pdf来预览在线pdf文件。但我总是得到空白页面,并且控制台上没有错误信息。我的代码是
<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
发布于 2021-04-17 04:09:59
不要重新分配变量src。您的挂载函数正在将src重新分配给其他对象,只需将其更改为:-
.....
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
})
}https://stackoverflow.com/questions/56327618
复制相似问题