uniapp 微信小程序webview安卓文件预览失败
uniapp 微信小程序 webview前 要判断设备 是安卓 还是苹果
是安卓直接下载打开文件
是苹果跳转webview预览
//获取设备类型
uni.getSystemInfo({
success: res => {
console.log(res.platform);
if (res.platform === 'android') {
uni.downloadFile({
url: config.Abc_Xieyi+'/abc_xieyi.pdf',
success: function(res) {
const filePath = res.tempFilePath;
uni.openDocument({
filePath: filePath,
success: function(res) {
console.log('打开文档成功');
}
});
}
});
} else {
uni.navigateTo({
url: '/pages/webview_pdf'//跳转webview
})
}
}
})
webview代码
<template>
<view>
<web-view :webview-styles="webviewStyles" :src="Http"></web-view>
</view>
</template>
<script>
import config from "@/util/config.js";
export default {
data() {
return {
Http:'',
webviewStyles: {
progress: {
color: '#FF3333'
}
},
}
},
onLoad(){
this.Http = config.Abc_Xieyi+'/abc_xieyi.pdf';
},
onShow() {
},
}
</script>
<style>
</style>