1.下载pdf.js文件(微信公众号使用的话建议使用2.4的版本,要不然会出现语法上的问题;
链接:https://pan.baidu.com/s/1NAwml6W-1bbozYQ46edHFA?pwd=61yy
提取码:61yy
2.复制解压后的文件到项目static/pdfjs 文件夹中
3.html
<web-view :src="filePath" class="web-view" />
4.js
onLoad(params) {
this.filePath = `/static/pdfjs/web/viewer.html?file=${ encodeURIComponent(params.path) }`
}
问题解释:
1.如果出现报错:file origin does not match viewer's
在下载的文件中找到web/viewer.js
注释以下代码:origin !== viewerOrigin && protocol !== "blob:"
2.如果版本太高,部分语法在微信公众号中预览空白问题
降低版本。目前使用的2.4版本是可以解决这个问题的