vue-pdf手机查看

11 篇文章 0 订阅

git地址

https://github.com/FranckFreiburger/vue-pdf#readme

安装

//cnpm 镜像也行
npm install --save vue-pdf

实现

预览

只有预览作用(查看当前pdf第一页)

 <!-- .vue代码 -->
 <template>
 <!-- 导入后使用pdf标签,src:pdf所在位置 -->
  <pdf src="./static/relativity.pdf"></pdf>
 </template>

<script>
import pdf from 'vue-pdf'
export default {
  components: {
    pdf
  }
}

查看全部pdf

<template>
  <div>
    <div class="pdf">
       <p class="zhong">
           <span @click="changePdfPage(0)" class="turn" :class="{grey: currentPage==1}">
           <el-button type="primary">上一页</el-button></span>
            {{currentPage}} / {{pageCount}}
           <span @click="changePdfPage(1)" class="turn" :class="{grey: currentPage==pageCount}">
           <el-button type="primary">下一页</el-button></span>
       </p>
       <pdf :src="src"
            :page="currentPage"
            @num-pages="pageCount=$event"
            @page-loaded="currentPage=$event"
            @loaded="loadPdfHandler"
       ></pdf>
  </div>
    
  </div>
</template>

<script>
import pdf from 'vue-pdf'
export default {
  name: '',
  components: {
    pdf
  },

  data () {
    return {
      pdfUrl:'',
      currentPage:0,
      src:'',
      pageCount:0,
			numPages: undefined,
    }
  },
  mounted() {
    //我用手机开的热点 192.168.43.107是ip,8888本地测试的端口号
    var qianurl="http://192.168.43.107:8888/resources/"
    //this.$route.query.keyY ->请求地址的参数值,参数名:keyY
    this.pdfUrl = qianurl+this.$route.query.keyY
    //第一页
    this.currentPage = 1;
    this.src = pdf.createLoadingTask(this.pdfUrl)
	
	},
  methods: {
   changePdfPage (val) { //翻页 
     if (val === 0 && this.currentPage > 1) {
         this.currentPage--
      }
     if (val === 1 && this.currentPage < this.pageCount) {
         this.currentPage++

      }
},
   // pdf加载时
     loadPdfHandler (e) {
       this.currentPage = 1 // 加载的时候先加载第一页
     }
  }
}
</script>

<style scoped>
 .zhong{
   text-align: center
 }
</style>

效果图片

第一页
第二页

参考链接

1.https://www.npmjs.com/package/vue-pdf
2.https://cnpmjs.org/package/vue-pdf

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值