做的比较简陋,将就用哈,自己优化也许
调用:
this.$refs.openPdf.preview(item.url)
使用:
<!-- pdf预览start -->
<previewPdf ref="openPdf"></previewPdf>
<!-- pdf预览end -->
引用:
import previewPdf from '@/components/preview-pdf/preview-pdf.vue' //pdf预览
<template>
<view>
</view>
</template>
<script>
export default {
data() {
return {
};
},methods:{
//预览pdf
preview(pdfUrl){
uni.showLoading({title: '加载中'});
let urlPath=pdfUrl.replace(/http:/g,"https:")
console.log(urlPath,pdfUrl,'pdf地址')
uni.downloadFile({
url: urlPath,
success: (rest) => {
let filePath = rest.tempFilePath
uni.openDocument({
filePath: filePath,
success: function(res) {
uni.hideLoading()
console.log('打开成功');
}
})
}
})
}
}
}
</script>
<style lang="less">
</style>
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。