1、下载PDF.js
下载地址http://mozilla.github.io/pdf.js/getting_started/#download
这里提供了3中形式,我们这里选择第一种形式。
- 压缩包中内容
- build文件夹中
- web文件夹中
我们要用到的就是web文件夹中的viewer.html
2、Vue项目中引入
- 在static文件夹中新建pdf文件夹,如下
- 在components文件夹中新建pdf文件夹,如下(可根据自己项目实际结构改动)
- pdf-index.vue中
- pdf-index.js中(vue组件写法,不深入)
3、Vue项目中使用
- 使用页面引入(注意事项:pdfSrc需要使用encodeURIComponent方法转义)
- 展示效果