._vue-pdf">
赞
踩
npm -i vue-pdf --save-dev
- import pdf from 'vue-pdf'
-
- components: {
- pdf
- },
-
- <pdf
- :page="currentPage"
- @num-pages="pageCount = $event"
- @loaded="loadPdfHandler"
- :src="loadingTask"
- ></pdf>
- <template>
- <div class="hello">
- {{currentPage}} / {{pageCount}}
- <button @click="prePage">上一页</button>
- <button @click="nextPage">下一页</button>
- <pdf
- :page="currentPage"
- @num-pages="pageCount = $event"
- @loaded="loadPdfHandler"
- :src="loadingTask"
- ></pdf>
- </div>
- </template>
-
- <script>
- import pdf from 'vue-pdf'
- export default {
- name: 'HelloWorld',
- components: {
- pdf
- },
- data () {
- return {
- loadingTask: './static/11.pdf',
- currentPage: 1,
- pageCount: 0
- }
- },
- mounted () {
- },
- methods: {
- prePage () {
- if (this.currentPage <= 1) return
- this.currentPage -= 1
- },
- nextPage () {
- if (this.currentPage >= this.pageCount) return
- this.currentPage += 1
- },
- loadPdfHandler (e) {
- console.log(e)
- this.currentPage = 1 // 加载的时候先加载第一页
- }
- }
- }
- </script>
-
- <!-- Add "scoped" attribute to limit CSS to this component only -->
- <style scoped>
- </style>

- <template>
- <div class="hello">
- <pdf
- v-for="i in numPages"
- :key="i"
- :src="src"
- :page="i"
- style="width: 100%"
- ></pdf>
- </div>
- </template>
-
- <script>
- import pdf from 'vue-pdf'
- export default {
- name: 'HelloWorld',
- components: {
- pdf
- },
- data () {
- return {
- // loadingTask: null,
- src: '',
- numPages: undefined
- }
- },
- mounted () {
- const url = './static/11.pdf'
- this.src = pdf.createLoadingTask(url)
- this.src.promise.then(pdf => {
- this.numPages = pdf.numPages
- })
- },
- methods: {
-
- }
- }
- </script>

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。