uniapp在手机端预览文件

javascript 复制代码
handlePdf(url) {
          	uni.showLoading({
					title: '加载中',
					mask: true,
				})
				wx.downloadFile({
					url: url,
					success: function(res) {
						console.log(res)
						uni.hideLoading()
						var filePath = res.tempFilePath
						uni.showLoading({
							title: '正在打开',
							mask: true,
						})
						wx.openDocument({
							filePath: filePath,
							fileType: 'pdf',
							success: function(res) {
								console.log(res)
								uni.hideLoading()
								console.log('打开文档成功')
							},
							fail: function(err) {
								uni.hideLoading()
								console.log('fail:' + JSON.stringify(err))
							},
						})
					},
					fail: function(err) {
						uni.hideLoading()
						console.log('fail:' + JSON.stringify(err))
					},
				})
},

url是文件的地址,使用wx.downloadFile将文件下载到本地,然后将文件使用wx.openDocument进行打开

相关推荐
brzhang4 分钟前
读懂 MiniMax Agent 的设计逻辑,然后我复刻了一个MiniMax Agent
前端·后端·架构
西洼工作室12 分钟前
高效管理搜索历史:Vue持久化实践
前端·javascript·vue.js
广州华水科技19 分钟前
北斗形变监测传感器在水库安全中的应用及技术优势分析
前端
樱花开了几轉26 分钟前
element ui下拉框踩坑
开发语言·javascript·ui
开发者如是说42 分钟前
Compose 开发桌面程序的一些问题
前端·架构
故事不长丨43 分钟前
【Java SpringBoot+Vue 实现视频文件上传与存储】
java·javascript·spring boot·vscode·后端·vue·intellij-idea
旺代1 小时前
Token 存储与安全防护
前端
洋不写bug2 小时前
html实现简历信息填写界面
前端·html
三十_A2 小时前
【无标题】
前端·后端·node.js
excel2 小时前
Vue 编译器源码解读:transformVBindShorthand 的设计与原理
前端