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

相关推荐
程序员小寒2 分钟前
前端性能优化之首屏时间采集篇
前端·性能优化
GGGG寄了3 分钟前
HTML——div和span标签和字符实体
前端·html
这儿有一堆花12 分钟前
网页开发的基石:深入解析 HTML 与 PHP 的本质差异
前端·html·php
RFCEO14 分钟前
网页编程 课程三、:HTML 核心规范(语义化+易维护)详解课程
前端·html·语义化·html核心规范·易维护·前端基础课
苦藤新鸡38 分钟前
27.合并有序链表,串葫芦
前端·javascript·链表
_OP_CHEN40 分钟前
【前端开发之HTML】(四)HTML 标签进阶:表格、表单、布局全掌握,从新手到实战高手!
前端·javascript·css·html·html5·网页开发·html标签
2501_916007471 小时前
如何查看 iOS 设备系统与硬件信息,iOS系统信息显示工具
android·ios·小程序·https·uni-app·iphone·webview
Alair‎1 小时前
前端开发之环境配置
前端·react.js
谢尔登1 小时前
Vue3底层原理——keep-alive
javascript·vue.js·ecmascript
Deca~1 小时前
VueVirtualLazyTree-支持懒加载的虚拟树
前端·javascript·vue.js