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进行打开

相关推荐
爱学习的程序媛4 分钟前
《JavaScript权威指南》核心知识点梳理
开发语言·前端·javascript·ecmascript
乐观主义现代人29 分钟前
go 面试
java·前端·javascript
1***Q7841 小时前
前端在移动端中的离线功能
前端
星环处相逢1 小时前
Nginx 优化与防盗链及扩展配置指南
服务器·前端·nginx
2501_941886861 小时前
多语言微服务架构下的微服务熔断与限流优化实践
javascript
tsumikistep1 小时前
【前后端】Vue 脚手架与前端工程结构入门指南
前端·javascript·vue.js
在繁华处1 小时前
JAVA实战:文件管理系统1.0
java·开发语言·前端
GISer_Jing1 小时前
SSE Conf大会分享支付宝xUI引擎:AI时代的多模态交互革命
前端·人工智能·交互
Aerelin1 小时前
爬虫playwright中的资源监听
前端·爬虫·js·playwright
WordPress学习笔记2 小时前
专业建外贸网站公司推荐
大数据·前端·人工智能