1、使用uni-pp开发微信小程序,上线之后发现Android手机无法加载览PDF,但ios可以。这里运用了 uni.openDocument
<template>
<view class="wenj" @click="file" >
点击查看文件
</view>
</template>
<script>
export default {
data() {
return {
attach_url: '',
}
},
onLoad(option) {
},
onShow() {
},
methods: {
file(){
uni.showToast({
title: '加载中',
duration: 5000,
icon:"loading"
});
uni.downloadFile({
url: this.attach_url, //文件名
success: function (res) {
var filePath = res.tempFilePath;
uni.openDocument({
filePath: filePath,
success: function (res) {
console.log('打开文档成功');
uni.hideToast();
}
});
}
});
}
},
}
</script>
<style lang="scss">
page {
background: #F9F9F9;
}
.wenj{
height: 100rpx;
display: flex;
justify-content: flex-end;
align-items: center;
font-size: 30rpx;
color: #008AFF;
}
</style>
这里使用了一个点击事件 因为如果直接使用加载会很慢,还没加载完用户已经退出来