vue在线查看pdf文件

1.引入组件

javascript 复制代码
npm install --save vue-pdf

2、pdf组件页面模板

javascript 复制代码
<template>
  <div class="scrollBox" >
    <el-dialog   :visible.sync="open" :top="1"  width="50%" append-to-body>
        <div slot="title">
          <el-page-header @back="open =false" content="简历"></el-page-header>
        </div>
        <pdf v-for="item in numPages" :key="item" :src="pdfSrc" :page="item" ref="pdf"></pdf>
    </el-dialog>


  </div>
</template>

<script>
import pdf from 'vue-pdf'
export default {
  //你的页面路由名称
  name: "Resume",
  components: {
    pdf
  },
  data() {
    return {
      pdfSrc:null,//简历地址
      numPages: null, // pdf 总页数
      open:false,//开关
    };
  },
  methods: {
    show(url){
      //调用界面传过来简历的地址
       this.pdfSrc = url;
      // 计算pdf页码总数
       this.getNumPages();
       //打开弹出框
        this.open = true;
    },

    getNumPages() {
      let loadingTask = pdf.createLoadingTask(this.pdfSrc)
      loadingTask.promise.then(pdf => {
        this.numPages = pdf.numPages;

      }).catch(err => {
        console.error('pdf 加载失败', err);
      })
    },

  }
};
</script>

3、引入组件到你的页面

javascript 复制代码
<!-- 引入组件,ref:调用组件方法用  -->
<Resume ref="showResume"  :title="resumeTitle"></Resume>
import Resumefrom "@/views/business/common/resume";

//调用方法
toResume(resumeUrl){
			//resumeUrl简历地址
      this.$refs.showResume.show(resumeUrl);
    },

</script>

效果:

相关推荐
Lhuu(重开版15 分钟前
CSS:动效布局动画
前端·css
Q***K5516 分钟前
前端构建工具
前端
laocooon52385788621 分钟前
创建了一个带悬停效果的“我的个人主页“按钮
前端
2013编程爱好者1 小时前
Vue工程结构分析
前端·javascript·vue.js·typescript·前端框架
小满zs2 小时前
Next.js第十一章(渲染基础概念)
前端
不羁的fang少年3 小时前
前端常见问题(vue,css,html,js等)
前端·javascript·css
change_fate3 小时前
el-menu折叠后文字下移
前端·javascript·vue.js
yivifu3 小时前
CSS Grid 布局详解(2025最新标准)
前端·css
o***Z4485 小时前
前端性能优化案例
前端
张拭心5 小时前
前端没有实际的必要了?结合今年工作内容,谈谈我的看法
前端·ai编程