uni-app附件下载预览 并解决打开附件时黑屏

javascript 复制代码
      // 预览附件
      perviewFile(file) {
        console.log('点击附件', file)
        var str=file.previewUrl
        var filType=str.split('.')
        console.log(filType,'filType')
        uni.downloadFile({
          url: ''
          success: function(res) {
            console.log('打开文档成功', res);
            if (res.statusCode == 200) {
              uni.saveFile({
                tempFilePath: res.tempFilePath,
                success: function(save) {
                  console.log('uni.saveFile---', save)
                  // 自动打开手机预览文件页面
                  uni.openDocument({
                    filePath: save.savedFilePath,
                    fileType: filType[1],
                    success: function(open) {
                      // 打开文件成功
                      console.log(open)
                    },
                    fail: function(err) {
                      console.log('err', err)
                    }
                  })
                },
                fail: function(err) {
                  console.log('fail-----err', err)
                }
              })
            } 
        });
      },

当时遇到一个问题 就是附件调用saveFile 之后调用 openDocument附件虽然打开了 但是一直黑屏 当时找了好久原因之后也一直问度娘 之后发现fileType在官网虽然不是必填项 但是不填的话他一直是黑屏 fileType支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx

相关推荐
hongkid4 分钟前
React Native 如何打包正式apk
javascript·react native·react.js
李少兄6 分钟前
简单讲讲 SVG:前端开发中的矢量图形
前端·svg
前端小万8 分钟前
告别 CJS 库加载兼容坑
前端·前端工程化
恋猫de小郭8 分钟前
Flutter 3.38.1 之后,因为某些框架低级错误导致提交 Store 被拒
android·前端·flutter
JarvanMo12 分钟前
Flutter 需要 Hooks 吗?
前端
光影少年22 分钟前
前端如何虚拟列表优化?
前端·react native·react.js
Moment23 分钟前
一杯茶时间带你基于 Yjs 和 reactflow 构建协同流程图编辑器 😍😍😍
前端·后端·面试
菩提祖师_37 分钟前
量子机器学习在时间序列预测中的应用
开发语言·javascript·爬虫·flutter
invicinble41 分钟前
对于前端数据的生命周期的认识
前端
PieroPc1 小时前
用FastAPI 后端 和 HTML/CSS/JavaScript 前端写一个博客系统 例
前端·html·fastapi