- vue-pdf 引入
import pdf from 'vue-pdf'
- temlate
<pdf v-for="i in numPages" :key="i" :src="src :page="i></pdf>"
- data
data() { return { numPages: '', src: '' } }
- components
components: { pdf }
- use
this.src = pdf.createLoadingTask('pdf地址')
this.src.promise.then(pdf => { this.numPages = pdf.numPages })
tips:
建议下载 pdfjs-dist 否则控制台抛错,不影响实际使用。
推荐版本 pdfjs-dist@2.5.207 vue-pdf@4.2.0