当前位置:网站首页>【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 {
// ......
}
}
边栏推荐
- 6.26CF模拟赛E:价格最大化题解
- 力扣刷题日记/day5/2022.6.27
- 大厂面试总结大全二
- Numpy 的仿制 2
- Imitation of numpy 2
- ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
- ThreadLocal原理与使用
- Microservice architecture debate between radical technologists vs Project conservatives
- How is the entered query SQL statement executed?
- Li Kou brush question diary /day3/2022.6.25
猜你喜欢
2022年字节跳动日常实习面经(抖音)
Digital "new" operation and maintenance of energy industry
What if the self incrementing ID of online MySQL is exhausted?
uni-app与uviewUI实现仿小米商城app(附源码)
Scala basic tutorial -- 19 -- actor
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
Mysql5.7 installation tutorial graphic explanation
Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii
How to modify icons in VBS or VBE
随机推荐
一种将Tree-LSTM的强化学习用于连接顺序选择的方法
Tutorial on the use of Huawei cloud modelarts (with detailed illustrations)
力扣刷题日记/day7/2022.6.29
MXNet对GoogLeNet的实现(并行连结网络)
How to open an account is safe,
TorchDrug教程
I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)
[go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
Li Kou brush question diary /day7/6.30
Caché JSON 使用JSON适配器
Just today, four experts from HSBC gathered to discuss the problems of bank core system transformation, migration and reconstruction
力扣刷题日记/day7/6.30
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
File processing examples of fopen, FREAD, fwrite, fseek
Esp32-c3 introductory tutorial questions ⑫ - undefined reference to ROM_ temp_ to_ power, in function phy_ get_ romfunc_ addr
Scala基础教程--17--集合
Machine learning concept drift detection method (Apria)
一、C语言入门基础
Scala basic tutorial -- 20 -- akka