当前位置:网站首页>【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 {
// ......
}
}
边栏推荐
- 2022 national CMMI certification subsidy policy | Changxu consulting
- Summary of subsidy policies across the country for dcmm certification in 2022
- 谷粒商城(一)
- 力扣刷题日记/day6/6.28
- Unity makes revolving door, sliding door, cabinet door drawer, click the effect of automatic door opening and closing, and automatically play the sound effect (with editor extension code)
- Neglected problem: test environment configuration management
- Li Kou brush question diary /day1/2022.6.23
- Microservice architecture debate between radical technologists vs Project conservatives
- Just today, four experts from HSBC gathered to discuss the problems of bank core system transformation, migration and reconstruction
- Halcon模板匹配
猜你喜欢
同事悄悄告诉我,飞书通知还能这样玩
能源行业的数字化“新”运维
TorchDrug教程
My colleagues quietly told me that flying Book notification can still play like this
Stars open stores, return, return, return
[HCIA continuous update] WAN technology
学习路之PHP--phpstudy创建项目时“hosts文件不存在或被阻止打开”
基于unity的愤怒的小鸟设计
Grain Mall (I)
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
随机推荐
vbs或vbe如何修改图标
Detailed explanation of the maturity classification of ITSS operation and maintenance capability | one article clarifies the ITSS certificate
Tutorial on the use of Huawei cloud modelarts (with detailed illustrations)
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
How to download files using WGet and curl
线上MySQL的自增id用尽怎么办?
机器学习概念漂移检测方法(Aporia)
How to improve development quality
Scala basic tutorial -- 15 -- recursion
ThreadLocal原理与使用
Scala基础教程--12--读写数据
ITSS运维能力成熟度分级详解|一文搞清ITSS证书
[209] go language learning ideas
6.26cf simulation race e: solution to the problem of price maximization
Scala basic tutorial -- 19 -- actor
TorchDrug教程
MXNet对GoogLeNet的实现(并行连结网络)
The controversial line of energy replenishment: will fast charging lead to reunification?
6.26CF模拟赛B:数组缩减题解
输入的查询SQL语句,是如何执行的?