._vue-pdf">
当前位置:   article > 正文

vue-pdf使用

vue-pdf

安装vue-pdf

npm -i vue-pdf --save-dev

 

引入使用

  1. import pdf from 'vue-pdf'
  2. components: {
  3. pdf
  4. },
  5. <pdf
  6. :page="currentPage"
  7. @num-pages="pageCount = $event"
  8. @loaded="loadPdfHandler"
  9. :src="loadingTask"
  10. ></pdf>

示例

pdf翻页

  1. <template>
  2. <div class="hello">
  3. {{currentPage}} / {{pageCount}}
  4. <button @click="prePage">上一页</button>
  5. <button @click="nextPage">下一页</button>
  6. <pdf
  7. :page="currentPage"
  8. @num-pages="pageCount = $event"
  9. @loaded="loadPdfHandler"
  10. :src="loadingTask"
  11. ></pdf>
  12. </div>
  13. </template>
  14. <script>
  15. import pdf from 'vue-pdf'
  16. export default {
  17. name: 'HelloWorld',
  18. components: {
  19. pdf
  20. },
  21. data () {
  22. return {
  23. loadingTask: './static/11.pdf',
  24. currentPage: 1,
  25. pageCount: 0
  26. }
  27. },
  28. mounted () {
  29. },
  30. methods: {
  31. prePage () {
  32. if (this.currentPage <= 1) return
  33. this.currentPage -= 1
  34. },
  35. nextPage () {
  36. if (this.currentPage >= this.pageCount) return
  37. this.currentPage += 1
  38. },
  39. loadPdfHandler (e) {
  40. console.log(e)
  41. this.currentPage = 1 // 加载的时候先加载第一页
  42. }
  43. }
  44. }
  45. </script>
  46. <!-- Add "scoped" attribute to limit CSS to this component only -->
  47. <style scoped>
  48. </style>

pdf平铺

  1. <template>
  2. <div class="hello">
  3. <pdf
  4. v-for="i in numPages"
  5. :key="i"
  6. :src="src"
  7. :page="i"
  8. style="width: 100%"
  9. ></pdf>
  10. </div>
  11. </template>
  12. <script>
  13. import pdf from 'vue-pdf'
  14. export default {
  15. name: 'HelloWorld',
  16. components: {
  17. pdf
  18. },
  19. data () {
  20. return {
  21. // loadingTask: null,
  22. src: '',
  23. numPages: undefined
  24. }
  25. },
  26. mounted () {
  27. const url = './static/11.pdf'
  28. this.src = pdf.createLoadingTask(url)
  29. this.src.promise.then(pdf => {
  30. this.numPages = pdf.numPages
  31. })
  32. },
  33. methods: {
  34. }
  35. }
  36. </script>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/880290
推荐阅读
相关标签
  

闽ICP备14008679号