vue在线查看pdf文件

1.引入组件

npm install --save vue-pdf

2、pdf组件页面模板

<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、引入组件到你的页面


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

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

</script>

效果:

在这里插入图片描述

相关推荐

  1. vue线预览excel、pdf、word文件

    2024-03-11 09:14:02       28 阅读
  2. vue使用pdf.js实现在线查看pdf文件

    2024-03-11 09:14:02       48 阅读
  3. office文件pdf线预览

    2024-03-11 09:14:02       37 阅读
  4. pdf 转html 线预览和查询

    2024-03-11 09:14:02       51 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-11 09:14:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-11 09:14:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-11 09:14:02       82 阅读
  4. Python语言-面向对象

    2024-03-11 09:14:02       91 阅读

热门阅读

  1. RabbitMQ

    RabbitMQ

    2024-03-11 09:14:02      35 阅读
  2. Docker入门指南: 创新的容器化技术

    2024-03-11 09:14:02       40 阅读
  3. 主流开发语言与环境介绍

    2024-03-11 09:14:02       45 阅读
  4. elementPlus的坑

    2024-03-11 09:14:02       43 阅读
  5. 各种环境下载链接

    2024-03-11 09:14:02       43 阅读
  6. 轻量脚本语言Lua的配置与c++调用

    2024-03-11 09:14:02       42 阅读
  7. linux系统Docker容器Dockerfile简单描述

    2024-03-11 09:14:02       43 阅读
  8. 创建旅游景点图数据库Neo4J技术验证

    2024-03-11 09:14:02       38 阅读
  9. PPT只要出现弹窗就闪退,Word和Excel都是正常的

    2024-03-11 09:14:02       192 阅读
  10. 玩转centos 下的core 文件

    2024-03-11 09:14:02       45 阅读
  11. python中Unicode 数据库访问(Unicode Character Database)

    2024-03-11 09:14:02       44 阅读