日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

记录一次微信小程序实现预览pdf

發布時間:2024/3/24 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 记录一次微信小程序实现预览pdf 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

微信小程序預覽pdf需要注意的是,在安卓端和ios端是有差異的。

安卓端不能用web-view直接打開,需要先下載到本地,再打開文件進行預覽。

網上說的ios端可以直接用web-view進行預覽,但是我使用ios預覽pdf時,報400錯誤。

尚未解決,記錄一下。

<template><view><web-view :webview-styles="webviewStyles" :src="fileUrl"></web-view></view> </template><script>import globalConfig from '@/config/config.js'export default {data() {return {fileUrl: null,};}, onLoad(option) {console.log(option);this.fileUrl = globalConfig.imageRootUrl+option.file;console.log(this.fileUrl);} } </script> //這里的 url 就是pdf文件的路徑,直接調用此方法就可以打開pdf文件openReport(url) {uni.showLoading({title: '加載中',mask: true})wx.downloadFile({url: url,success: function(res) {console.log(res)uni.hideLoading()var filePath = res.tempFilePath;uni.showLoading({title: '正在打開',mask: true})wx.openDocument({filePath: filePath,fileType: 'pdf',success: function(res) {console.log(res)uni.hideLoading()console.log('打開文檔成功');},fail: function(err) {uni.hideLoading()console.log('fail:' + JSON.stringify(err));}});},fail: function(err) {uni.hideLoading()console.log('fail:' + JSON.stringify(err));}});},navigateTo(url) {uni.navigateTo({url});},showPdf(){let self = this;switch (uni.getSystemInfoSync().platform) {case 'android':console.log('安卓')// 這里直接調用原生的方法,我們上面定義的self.openReport(globalConfig.imageRootUrl+self.evaluationSuitability.filePath)break;case 'ios':console.log('IOS')//這里跳轉web-view頁面self.navigateTo('/pages/evaluationSuitability/pdf?file='+self.evaluationSuitability.filePath)break;default:console.log('微信開發者工具')self.navigateTo('/pages/evaluationSuitability/pdf?file='+self.evaluationSuitability.filePath)break;}}

總結

以上是生活随笔為你收集整理的记录一次微信小程序实现预览pdf的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。