uniapp 預(yù)覽流文件pdf

開發(fā)中會遇到文件上傳的類型功能,上傳到對應(yīng)的數(shù)據(jù)庫了,可能用戶需要下載回來保存預(yù)覽和直接web預(yù)覽的形式打開,下面來總結(jié)一下uniapp 預(yù)覽流文件pdf的方式:
具體實現(xiàn)骨架屏方案:
第三方軟件預(yù)覽
webview打開
一、第三方軟件預(yù)覽
uni.downloadFile({ //通過uniapp的api下載下來url: 'test.pdf',success: function(res) {var filePath = res.tempFilePath;uni.openDocument({filePath: filePath,success: function(FileRes) {console.log('打開文檔成功');}});}});
二、webview打開
export default {data() {return {src: '',allUrl: '',viewerUrl: '/hybrid/html/web/viewer.html',}},onLoad(options) {let fileUrl = encodeURIComponent("pdf的地址") // encodeURIComponent 函數(shù)可把字符串作為 URI 組件進(jìn)行編碼。this.allUrl = this.viewerUrl + '?file=' + fileUrl}}//然后就傳路徑到webViewuni.navigateTo({url: '../filePreview?url=' + 你的pdf路徑})
評論
圖片
表情
