uni - 小程序端-预览打开在线pdf文件
uni.navigateTo({
url: '/pagesSub/my/webview?url='+encodeURIComponent('地址')
})
新创建一个页面:

<template> <web-view :src="url"></web-view> </template> <script> export default { data() { return { url: '', }; }, onLoad(options) { const src = decodeURIComponent(options.url); uni.downloadFile({ //将文档下载到本地 url: src, //pdf链接 success(res) { let filepathss = res.tempFilePath; uni.openDocument({ filePath: filepathss, fileType: 'pdf', success: function(res) { console.log(res,"resresres") console.log('打开文档成功'); }, fail: function(err) { console.log(err,"errrrr") uni.showToast({ title: '暂不支持此类型', duration: 2000, icon: 'none' }); } }); } }); }, methods: {} }; </script> <style></style>
参考链接:
https://uniapp.dcloud.net.cn/api/request/network-file.html
https://blog.csdn.net/blue__k/article/details/123401496
https://blog.csdn.net/weixin_41377835/article/details/126890525
本文仅提供参考,是本人闲时所写笔记,如有错误,还请赐教,作者:阿蒙不萌,大家可以随意转载
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架