使用uni-app开发微信小程序时遇到的问题:在Android设备上无法加载PDF文件,而iOS设备则可以正常加载。
<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>