uni-app预览pdf

126 阅读1分钟

1.下载pdf.js

下载地址:PDF.js - 主页 (mozilla.github.io)

image.png

2.解压后将文件放在项目下面

image.png

3.找到刚刚的文件里面viewer.html的路径

<script>
export default {
    data(){
        return {
            viewerUrl: '/jxzyysedu/wxh5/hybrid/html/web/viewer.html', //viewer.html的路径
        }
    },
 
    methods:{
        lookPdf(item){ 
            location.href = `${this.viewerUrl}?file=${encodeURIComponent(item.videoFile)}`;//item.videoFile是文件url
        },

}
</script>