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

相关推荐
求学中--12 小时前
状态管理一文通:@State、@Prop、@Link、@Provide/Consume全解析
人工智能·小程序·uni-app·wpf·harmonyos
求学中--12 小时前
ArkUI组件库完全指南:从基础组件到自定义装饰器
低代码·华为·小程序·uni-app·harmonyos
IT_陈寒12 小时前
JavaScript实战技巧总结
前端·人工智能·后端
玲小珑12 小时前
AI Coding 与 Harness 实践精髓:让AI高效干活、持续交付
前端·人工智能·openai
skilllite作者12 小时前
Agent-Skills 核心能力与实战效能深度评测
大数据·开发语言·前端·数据库·人工智能·python
恋猫de小郭12 小时前
实用性 Max ,新 Flutter & Dart Agent Skills 深度解读
android·前端·flutter
一诺加油鸭12 小时前
若依(RuoYi)框架中普通用户角色登录后访问接口报 403 “当前操作没有权限”错误的完整解决方案
前端
宁雨桥13 小时前
AI前端开发面试题分享
前端·人工智能·ai
亿元程序员13 小时前
求求你别卷了,主管又转发你的文章到工作群了...我看了之后五味杂陈,决定卷个毛线!
前端
kyriewen1113 小时前
你的前端滤镜慢得像PPT?用Rust+WebAssembly,一秒处理4K图
开发语言·前端·javascript·设计模式·rust·ecmascript·powerpoint