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>
View Code
复制代码

 

 

 

参考链接:

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

posted @   阿蒙不萌  阅读(784)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示