vue 使用 vue-pdf

168 阅读1分钟
  1. vue-pdf 引入

import pdf from 'vue-pdf'

  1. temlate

<pdf v-for="i in numPages" :key="i" :src="src :page="i></pdf>"

  1. data

data() { return { numPages: '', src: '' } }

  1. components

components: { pdf }

  1. 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