当前位置:网站首页>【uniapp】uniapp开发app在线预览pdf文件
【uniapp】uniapp开发app在线预览pdf文件
2022-07-04 17:09:00 【奄奄一息的一条咸鱼】
1.需要从网上下载一份pdf.js
的文件放到自己的项目中
2.除了pdf.html
文件,其他文件可以新建一个pdf
文件夹,统一放到该目录下,然后将pdf
文件夹放到项目的static
目录下,pdf.html
也单独的放到static
目录下,最终如下图所示:
3.要实现pdf预览,需要用到uniapp
的apiweb-view
,新建一个.vue
文件,写上如下代码:
<template>
<view class="webView">
<cu-custom isBack top :bgColor="NavBarColor">
<block slot="content">在线预览</block>
</cu-custom>
<web-view :src="urls"></web-view>
</view>
</template>
<script> export default {
data() {
return {
NavBarColor: this.NavBarColor, urls: '', } }, onLoad(params) {
let {
url: urls} = params // /static/pdf.html 就是自己放在static目录下的pdf.html文件位置 this.urls = `/static/pdf.html?url=${
urls}` } } </script>
4.点击某个pdf文件,跳转到刚刚新建的web-view
文件中,且需要携带url参数跳转,pdf.js
会根据url后的参数获取到的数据,生成pdf并渲染到页面中,如下所示:
seeVideo(item) {
if (item.subjectType === '文件') {
// pdf文件预览
uni.navigateTo({
// this.$config.staticDomainURL 是预览pdf文件的一个接口
// item.videos 拿到的是pdf文件的路径
url: '/pages/shop/webView?url=' + this.$config.staticDomainURL + '/' + item.videos
})
} else {
// ......
}
}
边栏推荐
- 基于unity的愤怒的小鸟设计
- 力扣刷题日记/day6/6.28
- Li Kou brush question diary /day1/2022.6.23
- Scala basic tutorial -- 13 -- advanced function
- [go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
- Halcon模板匹配
- 爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
- Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii
- Scala基础教程--14--隐式转换
- How to improve development quality
猜你喜欢
爬虫初级学习
Unity 制作旋转门 推拉门 柜门 抽屉 点击自动开门效果 开关门自动播放音效 (附带编辑器扩展代码)
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
TCP waves twice, have you seen it? What about four handshakes?
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
被忽视的问题:测试环境配置管理
Angry bird design based on unity
力扣刷題日記/day6/6.28
力扣刷题日记/day3/2022.6.25
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
随机推荐
[HCIA continuous update] network management and operation and maintenance
Wireshark packet capturing TLS protocol bar displays version inconsistency
The block:usdd has strong growth momentum
Microservice architecture debate between radical technologists vs Project conservatives
2022 ByteDance daily practice experience (Tiktok)
被忽视的问题:测试环境配置管理
MySQL常用增删改查操作(CRUD)
Lua EmmyLua 注解详解
Machine learning concept drift detection method (Apria)
TorchDrug教程
Redis master-slave replication
Scala basic tutorial -- 15 -- recursion
力扣刷題日記/day6/6.28
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
My colleagues quietly told me that flying Book notification can still play like this
删除二叉搜索树中的节点附图详解
[go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
基于unity的愤怒的小鸟设计
Li Kou brush question diary /day8/7.1
I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)