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

相关推荐
科研邪修法3 小时前
PDF新增页面文字与文本批注怎么区分?以双版本培训讲义为例
前端·css·pdf
武昌库里写JAVA3 小时前
SpringBoot+Vue 项目介绍
java·javascript·git·sql·ai
Lanwarf-前端开发5 小时前
Vue3 + Canvas/WebGL 雷达扫描可视化实战:PPI、RHI、VOL、SVOL 四种模式原理与实现
前端·javascript·vue.js·webgl
FRing035 小时前
vue3干货总结2(vue3生命周期、父子通信、模版引用、provide和inject)
开发语言·前端·vue.js·vue3
锋行天下7 小时前
langgraph 全栈项目(三)
前端·人工智能·后端
YIAN7 小时前
从 LangChain 到 DeepAgents:手把手拆解 createAgent、Middleware 与复杂 Agent
javascript·langchain·deepseek
锋行天下8 小时前
langgraph 全栈项目(二)
前端·人工智能·后端
冬夜Zis9 小时前
顺着作用域链和 outer 指针,一次性看懂闭包底层逻辑
javascript
Ceelog9 小时前
Mac 上怎么找出并安全清理旧的 node_modules?(实测 304 个占 66.3 GB)
javascript