uni - 小程序端-预览打开在线pdf文件
uni.navigateTo({
url: '/pagesSub/my/webview?url='+encodeURIComponent('地址')
})
新创建一个页面:
<template>
<web-view :src="url"></web-view>
</template>
<script>
export default {
data() {
return {
url: '',
};
},
onLoad(options) {
const src = decodeURIComponent(options.url);
uni.downloadFile({
//将文档下载到本地
url: src, //pdf链接
success(res) {
let filepathss = res.tempFilePath;
uni.openDocument({
filePath: filepathss,
fileType: 'pdf',
success: function(res) {
console.log(res,"resresres")
console.log('打开文档成功');
},
fail: function(err) {
console.log(err,"errrrr")
uni.showToast({
title: '暂不支持此类型',
duration: 2000,
icon: 'none'
});
}
});
}
});
},
methods: {}
};
</script>
<style></style>

参考链接:
https://uniapp.dcloud.net.cn/api/request/network-file.html
https://blog.csdn.net/blue__k/article/details/123401496
https://blog.csdn.net/weixin_41377835/article/details/126890525
本文仅提供参考,是本人闲时所写笔记,如有错误,还请赐教,作者:阿蒙不萌,大家可以随意转载

浙公网安备 33010602011771号