vue-pdf realizes online file preview

vue-pdf realizes online file preview

This article example shares the specific code of vue-pdf to realize online preview of files for your reference. The specific content is as follows

Tip: Record the usage of vue-pdf to avoid forgetting and facilitate later use

Preface

Tip: The following is the main content of this article. The following cases can be used for reference

1. Installation

npm install --save vue-pdf

2. PDF page display

1.html

<template>
 <div class="pdf-box">
 //pdf display<pdf
          class="pdf"
          :page="pageNum"
          :src="pdfForm.url"
          @progress="loadedRatio = $event"
          @num-pages="pageTotalNum = $event"
        ></pdf>
        //Page number switching <div class="page-box">
          <el-button-group>
            <el-button
              type="primary"
              icon="el-icon-arrow-left"
              size="mini"
              @click="prePage"
              >Previous page</el-button
            >
            <el-button type="primary" size="mini" @click="nextPage"
              >Next page<i class="el-icon-arrow-right el-icon--right"></i
            ></el-button>
          </el-button-group>
          //Page number display <div style=" color: #409EFF; display: flex; justify-content: flex-end;">
            {{ pageNum }} / {{ pageTotalNum }}
          </div>
        </div>
      </div>
</template>

2.javascript

<script>
import pdf from 'vue-pdf'
export default {
  name: 'pdf',
  components: { pdf },
  data () {
   pdfForm: { url: '' },
      // View pdf
      url:'',
      pageNum: 1,
      pageTotalNum: 1, // Total number of pages loadedRatio: 0 // Loading progress of the current page, the range is 0-1, when it is equal to 1, it means that the current page has been fully loaded},
  method:{
 //Previous page prePage () {
      let page = this.pageNum
      page = page > 1 ? page - 1 : this.pageTotalNum
      this.pageNum = page
    },

    // Next page nextPage () {
      let page = this.pageNum
      page = page < this.pageTotalNum ? page + 1 : 1
      this.pageNum = page
    },
  }
 }
</script>

Rendering

Summarize

Record the usage of vue-pdf to avoid forgetting it and to facilitate future use

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue implements online preview of PDF files and downloading (pdf.js)
  • Vue implements online preview function of PDF document
  • Vue plugin development: How to use pdf.js to realize online preview of PDF documents on mobile phones
  • Vue sample code for online preview of office files
  • Vue implements online preview of PDF files (using pdf.js/iframe/embed)
  • vue Sample code for using vue-pdf to implement PDF online preview
  • Vue-pdf implements online preview of PDF files
  • Online preview of three common file types in Vue projects (pdf/word/excel tables)

<<:  mysql8.0 forgotten password modification and net command service name invalid problem

>>:  Linux nohup command principle and example analysis

Recommend

Native JS to achieve book flipping effects

This article shares with you a book flipping effe...

js implements custom drop-down box

This article example shares the specific code of ...

TimePicker in element disables part of the time (disabled to minutes)

The project requirements are: select date and tim...

Nginx improves access speed based on gzip compression

1. Why does nginx use gzip? 1. The role of compre...

A detailed introduction to Linux file permissions

The excellence of Linux lies in its multi-user, m...

Tomcat Server Getting Started Super Detailed Tutorial

Table of contents 1. Some concepts of Tomcat –1, ...

Detailed tutorial for installing influxdb in docker (performance test)

1. Prerequisites 1. The project has been deployed...

Detailed explanation of the use of bus in Vue

Vue bus mechanism (bus) In addition to using vuex...

react-beautiful-dnd implements component drag and drop function

Table of contents 1. Installation 2.APi 3. react-...

How to use yum to configure lnmp environment in CentOS7.6 system

1. Installation version details Server: MariaDB S...

How to delete an image in Docker

The command to delete images in docker is docker ...