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

相关推荐
o***Z44839 分钟前
React自然语言
前端·react.js·前端框架
J***Q29242 分钟前
React部署方案详解
前端·react.js·前端框架
q***R30843 分钟前
React组件性能分析
前端·react.js·前端框架
5***79001 小时前
React趋势
前端·react.js·前端框架
1***y1781 小时前
React路径
前端·react.js·前端框架
m***D2861 小时前
React生态系统
前端·react.js·前端框架
b***74881 小时前
React计算机
前端·react.js·前端框架
q***T5831 小时前
React案例
前端·react.js·前端框架
闲人编程1 小时前
Python协程的演进:从yield到async/await的完整历史
java·前端·python·async·yield·await·codecapsule
驳是2 小时前
TS 项目升级 React 18 到 19 的一些事情
前端·react.js·typescript