前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >uniapp安卓-IOS打开pdf文件组件

uniapp安卓-IOS打开pdf文件组件

原创
作者头像
〆 千寻、
修改2020-03-17 09:49:51
3.5K4
修改2020-03-17 09:49:51
举报
文章被收录于专栏:技术分享文章技术分享文章

做的比较简陋,将就用哈,自己优化也许

调用:

代码语言:javascript
复制
this.$refs.openPdf.preview(item.url)

使用:

代码语言:javascript
复制
<!-- pdf预览start -->
<previewPdf ref="openPdf"></previewPdf>
<!-- pdf预览end -->

引用:

代码语言:javascript
复制
import previewPdf from '@/components/preview-pdf/preview-pdf.vue' //pdf预览

代码语言:javascript
复制
<template>
    <view>

    </view>
</template>

<script>
    export default {
        data() {
            return {

            };
        },methods:{
            //预览pdf
            preview(pdfUrl){
                uni.showLoading({title: '加载中'});
                let urlPath=pdfUrl.replace(/http:/g,"https:")
                console.log(urlPath,pdfUrl,'pdf地址')
                uni.downloadFile({
                    url: urlPath,
                    success: (rest) => {
                        let filePath = rest.tempFilePath
                        uni.openDocument({
                            filePath: filePath,
                            success: function(res) {
                                uni.hideLoading()
                                console.log('打开成功');
                            }
                        })
                    }
                })
            }
        }
    }
</script>

<style lang="less">

</style>

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档