当前位置:网站首页>【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 {
// ......
}
}
边栏推荐
- I wrote a learning and practice tutorial for beginners!
- 【OpenCV入门到精通之九】OpenCV之视频截取、图片与视频互转
- Lua emmylua annotation details
- 力扣刷题日记/day1/2022.6.23
- Pb extended DLL development (super chapter) (VII)
- Scala basic tutorial -- 20 -- akka
- 输入的查询SQL语句,是如何执行的?
- Android uses sqliteopenhelper to flash back
- 输入的查询SQL语句,是如何执行的?
- Wireshark抓包TLS协议栏显示版本不一致问题
猜你喜欢

I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)

Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers

MXNet对GoogLeNet的实现(并行连结网络)

What if the self incrementing ID of online MySQL is exhausted?

【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现

Li Kou brush question diary /day8/7.1

Angry bird design based on unity

Principle and application of ThreadLocal

基于unity的愤怒的小鸟设计

输入的查询SQL语句,是如何执行的?
随机推荐
Li Kou brush question diary /day4/6.26
[go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
An example of multi module collaboration based on NCF
MySQL常用增删改查操作(CRUD)
学习路之PHP--phpstudy创建项目时“hosts文件不存在或被阻止打开”
Redis master-slave replication
【211】go 处理excel的库的详细文档
Wireshark packet capturing TLS protocol bar displays version inconsistency
一直以为做报表只能用EXCEL和PPT,直到我看到了这套模板(附模板)
File processing examples of fopen, FREAD, fwrite, fseek
ITSS运维能力成熟度分级详解|一文搞清ITSS证书
力扣刷题日记/day8/7.1
输入的查询SQL语句,是如何执行的?
Scala基础教程--15--递归
Scala基础教程--19--Actor
Scala基础教程--12--读写数据
如何使用 wget 和 curl 下载文件
The block:usdd has strong growth momentum
Neglected problem: test environment configuration management
Load test practice of pingcode performance test