一、在本地浏览pdf(直接将element-dialog 和 iframe相结合)需要将要浏览的pdf放入static文件夹下面

  <el-button type="text" @click="dialogVisible = true">点击打开 Dialog</el-button>
<el-dialog
title="提示"
:visible.sync="dialogVisible">
<iframe src="../../static/文件名.pdf" width="90%" height="600px"></iframe>
</el-dialog>

在data中直接定义 dialogVisible

  data() {
return {
dialogVisible: false
}
}

以上方法便可直接在本地查看pdf,无需添加pdf.js

二、通过后台传来的数据,展示pdf

在展示之前,要先接收到后台的axios的数据

1.  api.js中定义

export const decision = data => ajaxHttp('/home/dynamic/decision/page', data, 'POST')

2.要接受的页面引入

import { decision } from '../api/api'

3.开始接收后台

    async getList () {
this.loading = true
let params = {
type: 1
}
const res = await decision(params)
if (res.data.code === 1) {
this.list = res.data.data
console.log(this.list)
} else {
this.$message({type: 'success', message: res.data.msg})
}
this.listNumber = this.list.length
this.loading = false
},

接收后不要忘记在mounted里面定义如何开始

mounted () {
this.getList()
}

4.定义一下显示出来的和点击事件的位置

  <div v-for="item in list" :key="item.id" @click="clickPDFfn(item.filePath1)">{{item.title}}</div>

5.定义el-dialog (定义之前要先引入,查看element.api)

<el-dialog
:visible.sync="otherDialogVisible"
width="80%"
center>
<span>
<canvas id="canvas1"></canvas>
<div class="foot" v-if='pdfDoc'>
<el-button class='left' v-if="pageNum>1" @click="onPrevPage">上一页</el-button>
<el-button class='right' v-if="pageNum<pdfDoc.numPages" @click="onNextPage">下一页</el-button>
</div>
</span>
</el-dialog>

6.写下如下方法

handleCurrentChange (val) {
this.currentPage = val
},
clickPDFfn (item) {
this.loading = true
this.otherDialogVisible = true
this.showPDF('http://compre-tj-api.gov.bbdtek.com/repository/readPDF?path=' + item)
},
showPDF (url) {
let _this = this
this.$pdf.getDocument(url).then(function (pdf) {
_this.pdfDoc = pdf
_this.$nextTick(() => {
_this.renderPage(1)
})
})
},
renderPage (num) {
this.pageRendering = true
let _this = this
this.pdfDoc.getPage(num).then(function (page) {
let canvas = document.getElementById('canvas1')
let ctx = canvas.getContext('2d')
let dpr = window.devicePixelRatio || 1
let bsr = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
ctx.oBackingStorePixelRatio ||
ctx.backingStorePixelRatio || 1
let ratio = dpr / bsr
let viewport = page.getViewport(screen.availWidth / page.getViewport(1).width)
canvas.height = viewport.height * ratio
canvas.width = viewport.width * ratio
canvas.style.width = '100%'
canvas.style.height = '100%'
ctx.setTransform(ratio, 0, 0, ratio, 0, 0)
// Render PDF page into canvas context
var renderContext = {
canvasContext: canvas.getContext('2d'),
viewport: viewport
}
var renderTask = page.render(renderContext) // Wait for rendering to finish
renderTask.promise.then(function () {
_this.pageRendering = false
if (_this.pageNumPending !== null) {
// New page rendering is pending
this.renderPage(_this.pageNumPending)
_this.pageNumPending = null
}
})
})
},
queueRenderPage (num) {
console.log(num)
if (this.pageRendering) {
this.pageNumPending = num
} else {
this.renderPage(num)
}
},
onPrevPage () {
if (this.pageNum <= 1) {
return
}
this.pageNum--
this.queueRenderPage(this.pageNum)
},
onNextPage () {
if (this.pageNum >= this.pdfDoc.numPages) {
return
}
this.pageNum++
this.queueRenderPage(this.pageNum)
}

7.添加以下属性

data () {
return {
listNumber: 0,
loading: false,
otherDialogVisible: false,
pdfDoc: null,
pageNum: 1,
pageNumPending: null,
currentPage: 1,
list: []
}
}

通过以上方法即可连接后台直接浏览pdf

注: 后台pdf地址定义为 filePath1

蒙层嵌套pdf以及连接后台的更多相关文章

  1. MongoDB学习笔记~大叔框架实体更新支持N层嵌套~递归递归我爱你!

    回到目录 递归递归我爱你!只要你想做,就一定能成功! 从一到二,从二到三,它是容易的,也是没什么可搞的,或者说,它是一种流水线的方式,而从三到十,从十到百,它注定要有一个质的突破,否则,它会把你累死, ...

  2. 设置 tableview 的背景颜色,总是有蒙层

    1.给tableview添加了背景图片后, cell 总是有一层蒙层蒙着,很阴暗. 2.实验以后才发现背景图片被放在了 cell 的后面.

  3. css-dialog样式实现弹框蒙层全屏无需JS计算高度兼容IE7

    <!DOCTYPE html><html><head>  <meta charset="UTF-8">  <title> ...

  4. css 蒙层

    蒙层 利用z-index: .mui-backdrop-other { position: fixed; top: 44px; right:; bottom:; left:; z-index:; ba ...

  5. iOS开发之实现半透明蒙层背景效果[用于下拉菜单页和分享页]

    郝萌主倾心贡献.尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助.欢迎给作者捐赠.支持郝萌主,捐赠数额任意.重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 游戏官方下 ...

  6. appium-在页面点击一下处理(一般处理提示蒙层)

    在写用例的时候,经常会发现某些第一次进去的页面会有一个蒙层提示.我们只有处理掉这个蒙层,才能继续我们的用例: 这边我们使用的是TouchAction的tap方法 TouchAction action ...

  7. vue 连接后台

    在 index.js 中可以配置后台的地址:代理的方式: 这个文件在 config 中 proxyTable: { // 连接后台 '/api':{ target:"http://new.w ...

  8. 用Loading 加载中的整页加载来做蒙层

    总结:遇见的bug 如何写一个蒙层 最初我打算的是自己写一个蒙层,但是写出来后, 不能够将整个屏幕全部覆盖.只能够覆盖 除[顶部导航] 和[左侧菜单栏] 于是我就使用了element-ui中的 [Lo ...

  9. vue 鼠标移入移出 列表蒙层展示

    <template> <section class="base"> <ul> <li v-for="(item, index) ...

随机推荐

  1. HDOJ1312 Red and black(DFS深度优先搜索)

    There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A ...

  2. Introducation of Servlet filter(servlet过滤器介绍 )

    本文章向大家介绍Servlet Filter,主要包括 Servlet Filter使用实例.应用技巧.基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下. 过滤器是一个可以转换 ...

  3. 清除本地SVN信息

    C:\Documents and Settings\yangxf\Application Data\Subversion\auth 这个目录下删除svn文件夹即可

  4. Native App自动化测试及Appium框架介绍

    一  自动化工具简介 1 Appium : 开源,跨平台的自动化测试工具,用于测试Native(原生)和Hybrid(混合)应用,支持IOS/Android/FirefoxOS 平台. 2  环境 : ...

  5. [十二省联考2019]异或粽子 01trie

    [十二省联考2019]异或粽子 01trie 链接 luogu 思路 首先求前k大的(xo[i]^xo[j])(i<j). 考场上只想到01trie,不怎么会写可持久,就写了n个01trie,和 ...

  6. bootstrap table 分页序号递增问题 (转)

    原文地址:https://segmentfault.com/q/1010000011040346 如题,怎么在bootstrap table中显示序号,序号递增,并且分页有效,等于是每页10条,第2页 ...

  7. Linux下SSH远程连接断开后让程序继续运行解决办法

    一.screen安装 yum  install screen   #CentOS安装 sudo apt-get install screen #ubuntu安装 二.screen常用命令 screen ...

  8. Caffe on Mac OS X 10.11

    在Mac环境安装Caffe环境(CPU_ONLY) http://blog.csdn.net/xidiancoder/article/details/52081519   有问题 http://blo ...

  9. python webdriver api-对启动的火狐浏览器添加配置

    Webdriver启用的火狐不带插件,可以自已进行配置 先找到火狐的安装路径 C:\Program Files\Mozilla Firefox 步骤说明 在CMD中使用cd命令进入firefox.ex ...

  10. Confluence 6 从 WIKI 标记整合到基于 XHTML 的存储格式

    如果你现在正在将 Confluence 从一个老的版本升级到 Confluence 4.0 或者更新的版本 (例如从 Confluence 3.5.x 或者更老的版本),在升级的过程中一个内容整合过程 ...