//一個是通過第三方軟件查看pdf uni.downloadFile({ //通過uniapp的api下載下來 url: 'test.pdf', success: function (res) { var filePath = res.tempFilePath; uni.openDocument({ filePath: filePath, success: function (FileRes) { console.log('打開文檔成功'); } }); } }); //另一種是通過pdf.js在uniapp中查看的 //新建webView.vue <template> <view style="width: 100%;" > <web-view :src="allUrl"></web-view> </view> </template> <script> export default { data() { return { src: '', allUrl:'', viewerUrl: '/hybrid/html/web/viewer.html', // 格式化文件流的一個js 文件 文末會分享出來 } }, onLoad(options) { let fileUrl = encodeURIComponent("pdf的地址") // encodeURIComponent 函數可把字符串作為 URI 組件進行編碼。 this.allUrl = this.viewerUrl + '?file=' + fileUrl } } </script> ////////////////////////////////////////////////// //然后引入文件夾hybrid放在項目根目錄下 //然后就傳路徑到webView //列如 uni.navigateTo({ url:'../filePreview?url='+你的pdf路徑 }) //附上pdf文件鏈接:https://pan.baidu.com/s/1TMj1b5v6AX-orYJNYZCFGQ 提取碼:2020