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

The difference between html block-level tags and inline tags

1. Block-level element: refers to the ability to e...

Usage of Node.js http module

Table of contents Preface HTTP HTTP Server File S...

Solution to Linux QT Kit missing and Version empty problem

Currently encountering such a problem My situatio...

Detailed summary of MySQL and connection-related timeouts

MySQL and connection related timeouts Preface: To...

Detailed explanation of how to view MySQL memory usage

Preface This article mainly introduces the releva...

A brief analysis of adding listener events when value changes in html input

The effect to be achieved In many cases, we will ...

Add a copy code button code to the website code block pre tag

Referring to other more professional blog systems...

MySQL 8.0.12 installation configuration method and password change

This article records the installation and configu...

MYSQL METADATA LOCK (MDL LOCK) theory and lock type test

Table of contents MYSQL METADATA LOCK (MDL LOCK) ...

A brief discussion on MySQL index optimization analysis

Why are the SQL queries you write slow? Why do th...

HTML table tag tutorial (32): cell horizontal alignment attribute ALIGN

In the horizontal direction, you can set the cell...

React introduces antd-mobile+postcss to build mobile terminal

Install antd-mobile Global import npm install ant...

Implementation of FIFO in Linux process communication

FIFO communication (first in first out) FIFO name...

CocosCreator ScrollView optimization series: frame loading

Table of contents 1. Introduction 2. Analysis of ...