一,pdf.js下载地址https://sourceforge.net/projects/pdf-js.mirror/files/


下载版本太高,需要node版本达到22.0,否则会报Promise.withResolvers is not a function
二,将下载好的包解压并放到static目录里的pdfview中


三,找到web里的viewer.mjs文件,隐藏框里内容,不然会报file origin does not match viewer's错误

四,新建一个webView.vue文件
<template>
<view style="width: 100%;height: 100%;">
<web-view :src="webUrl"></web-view>
</view>
</template>
<script>
export default {
data(){
return{
webUrl:null,
pdfViewUrl: '/static/pdfview/web/viewer.html'
}
},
onLoad(options){
if(options.url){
this.webUrl = decodeURI(options.url)
this.webUrl = this.pdfViewUrl + '?file=' + encodeURI(this.webUrl)
}
}
//https://view.officeapps.live.com/op/view.aspx?src=""
//options.url是上一个页面传过来的pdf文件
}
</script>
<style>
</style>
效果预览


2915

被折叠的 条评论
为什么被折叠?



