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

相关推荐
chilavert3181 天前
技术演进中的开发沉思-371:final 关键字(中)
java·前端·数据库
2301_816997881 天前
Vite构建工具
前端
yuki_uix1 天前
深入理解 reduce:从面试题到设计思维
前端
凌云拓界1 天前
TypeWell全攻略(二):热力图渲染引擎,让键盘发光
前端·后端·python·计算机外设·交互·pyqt·数据可视化
coding随想1 天前
TypeScript 高级类型全攻略:从“可表达性”到“类型体操”的实践之路
前端·javascript·typescript
大时光1 天前
gsap -滚动插件 ScrollTrigger 简单demo
前端
tangbin5830851 天前
iOS Swift:蓝牙 BLE 连接外设CoreBluetooth
前端
WWWWW先生1 天前
02 登录功能实现
前端·javascript