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 @ 2023-05-19 09:59  阿蒙不萌  阅读(724)  评论(0编辑  收藏  举报