美文网首页
uni-app 小程序、H5预览excle、pdf、word等文

uni-app 小程序、H5预览excle、pdf、word等文

作者: 默色留恋 | 来源:发表于2023-06-06 15:43 被阅读0次
<text 
    class="u-collapse-content" 
    v-for="(i,ind) in item.content" 
    :data-url="httpUrl+i.title"   
    @click="previewFile">
    {{i.title}}
</text>
    

previewFile() {
      let url = e.currentTarget.dataset.url;
      uni.showLoading({
        title: '加载中'
       })

            uni.downloadFile({
                url: url , //后端返回的文件地址
                success: function(res) {
                    if (res.statusCode === 200) {
                        uni.openDocument({
                            filePath: res.tempFilePath,
                            success: function(res) {
                                console.log(res, '打开文件成功')
                            },
                            fail: (err) => {
                                uni.showToast({
                                    title: '打开文件失败请重试',
                                    icon: 'none'
                                })
                            }
                        })
                    } else {
                        uni.showToast({
                            title: '打开文件失败请重试',
                            icon: 'none'
                        })
                    }
                    uni.hideLoading()
                },
                fail: (err) => {
                    uni.hideLoading()
                    uni.showToast({
                        title: '加载失败请重试',
                        icon: "none"
                    })
                }
            })

        }

相关文章

网友评论

      本文标题:uni-app 小程序、H5预览excle、pdf、word等文

      本文链接:https://www.haomeiwen.com/subject/ilygedtx.html