Vue实现移动端打开pdf文件,滑动显示下一页
第一步,项目终端输入
npm install vue-pdf -save
第二步,直接在文件使用
<script>
<template>
<div class="pdf">
<pdf v-for="i in numPages" :key="i" :src="src" :page="i"></pdf>
</div>
</template>
import pdf from 'vue-pdf'
export default {
components: {
pdf
},
data() {
return {
currentPage: 0, // pdf文件页码
pageCount: 0, // pdf文件总页数
src: '', // pdf路径
numPages: 0
},
mounted() {
var url = '' // 文件地址
this.src = pdf.createLoadingTask(url)
this.src.promise.then((pdf) => {
this.numPages = pdf.numPages
})
},
}
</script>
这样就实现了 是不是很简单!