1.下载pdf.js
地址:https://github.com/mozilla/pdf.js/releases/download/v2.4.456/pdfjs-2.4.456-dist.zip)
2.复制到项目中
3.页面中使用
html:
<web-view class="web-view" :src="pdfUrl"></web-view>
js:
if (this.fileUrl) { this.pdfUrl = `/static/pdfjs/web/viewer.html?file=${ encodeURIComponent(this.fileUrl) }`; }
4.遇到的问题:
解决办法:
在viewer.js中找到以下代码并进行注释就可以解决
// if (origin !== viewerOrigin && protocol !== "blob:") { // throw new Error("file origin does not match viewer's"); // }
注:盖章无法解决的方法:
1.找到如下文件
2.注释掉如下代码