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

相关推荐
GIS之路1 小时前
ArcGIS Pro 中的 Notebooks 入门
前端
IT_陈寒2 小时前
React状态管理终极对决:Redux vs Context API谁更胜一筹?
前端·人工智能·后端
Kagol3 小时前
TinyVue 支持 Skills 啦!现在你可以让 AI 使用 TinyVue 组件搭建项目
前端·agent·ai编程
柳杉3 小时前
从零打造 AI 全球趋势监测大屏
前端·javascript·aigc
simple_lau3 小时前
Cursor配置MasterGo MCP:一键读取设计稿生成高还原度前端代码
前端·javascript·vue.js
睡不着先生3 小时前
如何设计一个真正可扩展的表单生成器?
前端·javascript·vue.js
天蓝色的鱼鱼4 小时前
模块化与组件化:90%的前端开发者都没搞懂的本质区别
前端·架构·代码规范
明君879974 小时前
Flutter 如何给图片添加多行文字水印
前端·flutter
进击的尘埃4 小时前
AI 代码审查工具链搭建:用 AST 解析 + LLM 实现自动化 Code Review 的前端工程方案
javascript
juejin_cn4 小时前
[转][译] 从零开始构建 OpenClaw — 第五部分(对话压缩)
javascript