技术标签: vue.js javascript
npm安装:npm install --save vue-pdf
1.多页上拉加载页面
<template>
<div class="pre_lump">
<div class="choice_box">
<div class="form-data">
<div class="pdf" id="example">
<pdf
ref="pdf"
v-for="i in numPages"
:key="i"
:src="pdfUrl"
:page="i"
></pdf>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import pdf from 'vue-pdf'
export default {
components:{
pdf
},
props:{
url:{
type:String,
default:''
}
},
data(){
return {
pdfUrl:"",
numPages: null, // pdf 总页数
}
},
mounted() {
this.pdfUrl = this.url
this.getNumPages()
},
methods: {
getNumPages() {
let loadingTask = pdf.createLoadingTask(this.url)
loadingTask.promise.then(pdf => {
this.numPages = pdf.numPages
}).catch(err => {
console.error('pdf 加载失败', err);
})
}
}
}
</script>
<style>
/* 弹窗的外层样式 */
.pre_lump {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.6);
z-index: 1111;
}
.pre_lump .choice_box {
position: absolute;
width: 50%;
min-width: 850px;
height: 100%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #ffffff;
border-radius: 2px;
}
#example {
width: 100%;
height: 100%;
}
.top_tips {
margin: 0 20px;
height: 54px;
line-height: 54px;
border-bottom: 1px solid rgb(233, 233, 233);
}
.top_tips .tips {
font-size: 18px;
font-weight: 500;
color: #333333;
}
.top_tips i {
font-size: 18px;
color: #333333;
}
.bot_bottom_bot {
position: absolute;
right: 2%;
bottom: 3%;
border-top: 1px solid rgb(233, 233, 233);
}
.form-data {
width: 100%;
padding: 0 20px;
box-sizing: border-box;
height: calc(100% - 60px);
margin: 15px auto;
overflow-y: auto;
}
.pagination {
position: absolute;
left: 50%;
bottom: 0%;
transform: translate(-50%, 0%);
background-color: #ccc;
text-align: center;
padding: 0 10px;
user-select: none;
height: 30px;
line-height: 30px;
}
.pagination .arrow2 span {
cursor: pointer;
display: inline-block;
background-color: #e53935;
color: #fff;
padding: 4px 6px;
font-size: 12px;
border-radius: 6px;
}
.close {
width: 34px;
height: 34px;
margin: 10px 0;
display: flex;
cursor: pointer;
align-items: center;
justify-content: center;
}
.close .el-icon-close {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
</style>
预览效果:
2.单页面点击上一页下一页加载页面
<template>
<div class="pre_lump">
<div class="choice_box">
<div class="form-data">
<div class="pdf" id="example">
<pdf
ref="pdf"
v-if="pdfSrc"
:src="pdfSrc"
:page="currentPage"
@num-pages="pageCount = $event"
@page-loaded="currentPage = $event"
@loaded="loadPdfHandler"
>
</pdf>
</div>
</div>
<div class="pagination">
<p class="arrow2" v-if="pdfSrc">
<el-button
type="primary"
size="mini"
@click="changePdfPage(0)"
:disabled="currentPage == 1"
>上一页</el-button
>
{
{ currentPage }} / {
{ pageCount }}
<el-button
type="primary"
size="mini"
@click="changePdfPage(1)"
:disabled="currentPage == pageCount"
>下一页</el-button
>
</p>
</div>
</div>
</div>
</template>
<script>
import pdf from "vue-pdf";
export default {
components: {
pdf
},
data() {
return {
pdfSrc: "https://dakaname.oss-cn-hangzhou.aliyuncs.com/file/2018-12-28/1546003282521.pdf",
currentPage: 0, // pdf文件页码
pageCount: 0, // pdf文件总页数
numPages: 1,
activeIndex: 0,
};
},
methods: {
// 改变PDF页码,val传过来区分上一页下一页的值,0上一页,1下一页
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 >
/* 弹窗的外层样式 */
.pre_lump {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.6);
z-index: 1111;
}
.pre_lump .choice_box {
position: absolute;
width: 50%;
min-width: 850px;
height: 100%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #ffffff;
border-radius: 2px;
}
#example {
width: 100%;
height: 100%;
}
.top_tips {
margin: 0 20px;
height: 54px;
line-height: 54px;
border-bottom: 1px solid rgb(233, 233, 233);
}
.top_tips .tips {
font-size: 18px;
font-weight: 500;
color: #333333;
}
.top_tips i {
font-size: 18px;
color: #333333;
}
.bot_bottom_bot {
position: absolute;
right: 2%;
bottom: 3%;
border-top: 1px solid rgb(233, 233, 233);
}
.form-data {
width: 100%;
padding: 0 20px;
box-sizing: border-box;
height: calc(100% - 60px);
margin: 15px auto;
overflow-y: auto;
}
.pagination {
position: absolute;
left: 50%;
bottom: 0%;
transform: translate(-50%, 0%);
background-color: #ccc;
text-align: center;
padding: 0 10px;
user-select: none;
height: 30px;
line-height: 30px;
}
.pagination .arrow2 span {
cursor: pointer;
display: inline-block;
background-color: #e53935;
color: #fff;
padding: 4px 6px;
font-size: 12px;
border-radius: 6px;
}
.close {
width: 34px;
height: 34px;
margin: 10px 0;
display: flex;
cursor: pointer;
align-items: center;
justify-content: center;
}
.close .el-icon-close {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.el-icon-close:hover {
color: red;
background-color: #f0f0f0;
border-radius: 50%;
}
</style>
预览效果:
3.html页面引入jquery实现pdf文件的在线预览
pdf.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>在线预览PDF文档</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.media.js"></script>
<script type="text/javascript">
$(function() {
$('a.media').media({width:800, height:900});
});
</script>
</head>
<body>
<center>
<div class="panel-body">
<a class="media" href="https://dakaname.oss-cn-hangzhou.aliyuncs.com/file/2018-12-28/1546003237411.pdf"></a>
</div>
</center>
</body>
</html>
预览效果:
以下线上pdf文件地址提供测试
pdfUrl1:“https://dakaname.oss-cn-hangzhou.aliyuncs.com/file/2018-12-29/1546049718768.pdf”
pdfUr2l:“http://file.gp58.com/file/2018-11-14/111405.pdf”
pdfUrl3:“https://dakaname.oss-cn-hangzhou.aliyuncs.com/file/2018-12-28/1546003237411.pdf”
pdfUrl4:“https://dakaname.oss-cn-hangzhou.aliyuncs.com/file/2018-12-28/1546003282521.pdf”
为什么80%的码农都做不了架构师?>>> ..._mysql-front密码错误
为什么80%的码农都做不了架构师?>>> ...
1.网络拓扑图链接:https://pan.baidu.com/s/1rIl5YcV-5JH0L8QQ06UqzA提取码:8888eNSP链接:https://pan.baidu.com/s/1wP0vHim4yqVV0bc0wmzhFw提取码:88882、网络需求a. 在网络中部署OSPF,使得全网的路由实现互通。b. SW1没有在VLAN10及VLAN20中激活OSPF,为了让OSPF设备SW2学习到这两个VLAN的路由,需要在SW1上将这两个VLAN的直连路由注入到OSPF中。c._重发布直连路由
2019独角兽企业重金招聘Python工程师标准>>> ..._om.readvalue 泛型
处理数据库关系对象组件时会用到这个奇怪的语法,下面参照中的例子结合嵌套表解释这个语法首先建立嵌套表create or replace type emp_typeas object(empno number(4),ename varchar2(10),job varchar2(9),mgr number(4),hiredate date,..._multiset oracle
nmap概念NMap,也称为网络映射器,最初是Linux下的网络扫描和嗅探工具包。Nmap是一种网络连接扫描软件,用于扫描网络计算机的开放网络连接端。确定哪些服务在哪些..._python-namp 域名收集
1、LuaComponent组件 LuaComponent主要有Get和Add两个静态方法,其中Get相当于UnityEngine中的GetComponent方法,Add相当于AddComponent方法,只不过这里添加的是lua组件不是c#组件。每个LuaComponent拥有一个LuaTable(lua表)类型的变量table,它既引用上述的Component表。Add方法使用AddCompo_lua 获取组件
仿真鸟群实现与解析思路解析List item_鸟群的社会仿真实验三个规则是什么
机器学习入门系列(2)--如何构建一个完整的机器学习项目,第九篇!常用机器学习算法汇总比较的最后一篇,介绍提升(Boosting)算法、GBDT、优化算法和卷积神经网络的基本原理、优缺点。9. 提升(Boosting)方法简述 提升方法(boosting)是一种常用的统计学习方法,在分类问题中,它通过改变训练样本的权重,学习多个分类器,并将这些分类器进行线性组合,提供分类的性能。 boosting 和 baggingboosting 和 bagging 都是集成学习(ensemble learning)领域_out-of-bag auc
这篇随笔对应的.Net命名空间是System.Xml.Serialization;文中的示例代码需要引用这个命名空间。为什么要做序列化和反序列化?.Net程序执行时,对象都驻留在内存中;内存中的对象如果需要传递给其他系统使用;或者在关机时需要保存下来以便下次再次启动程序使用就需要序列化和反序列化。范围:本文只介绍xml序列化,其实序列化可以是二进制的序列化,也可以是其他格式的序列化。..._xml 反序列化对象
1 在英伟达官网下载相应驱动搜索出相应的驱动后,不要直接点,而是右健,Save Link as...否则,会出现下载半天没动静的情况。存放的路径上最好不要有中文。我存放的路径是 ~/Downloads/NVIDIA-Linux-x86_64-346.47.run2 屏蔽默认带有的nouveau使用su命令切换到root用户下: su root打开/lib/modpr
Modularity介绍2006年Newman在文献Modularity and community structure in networks中提出了modularity的概念,并将其作为一种在网络和图中使用的度量方法。它可以衡量社区划分的好坏程度。modularity高,代表着社区内节点联系紧密,而社区间连接稀疏。modularity经常被用在社区发现的最优化算法中。然而modularit_网络modularity