相关文章推荐
一身肌肉的烈马  ·  R::Error in argument ...·  1 年前    · 
唠叨的豆芽  ·  datacontext - WPF: ...·  1 年前    · 
越狱的蚂蚁  ·  [netty]-入门案例 - ...·  1 年前    · 
< script > const PDFJS = require ( 'pdfjs-dist' ) PDFJS . GlobalWorkerOptions . workerSrc = 'https://cdn.jsdelivr.net/npm/pdfjs-dist@2.13.216/build/pdf.worker.js' export default { data ( ) { return { pdfPages : '' // 页数 mounted ( ) { this . getPdfUrl ( ) methods : { getPdfUrl ( ) { // todo 请求后台,获取pdf的url,这里用的是线上的地址 const url = 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf' const loadingTask = PDFJS . getDocument ( url ) loadingTask . promise . then ( pdf = > { this . pdfPages = pdf . numPages < / script > < style lang = "less" scoped > . preview - pdf { margin : 30 px auto ; text - align : center ; font - family : '宋体' ; letter - spacing : 2 px ; < / style > 问题描述:页面展示多个 pdf 文件,且每个 PDF 文件有自己的分页,分页之间不会互相干扰。 问题解决方案:将分页设置为一个数组,先定义一个空的数组,然后 获取 总文件个数进行循环,每循环一次,在空数组中push当前页,总 页数 这些变量,然后在页面进行渲染。 1. 定义空数组 data () { return { pathList: [], currentArr: [], fileType: ' pdf ', // 文件类型 src: '', // pdf 文件 <template> <div class="wrap"> < pdf v-for="item in numPages" :key="item" :src=" pdf Src" :page="item"/> </template> <script> import pdf from ' vue - pdf ' import