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

相关推荐
程序员鱼皮17 分钟前
又被 Cursor 烧了 1 万块,我麻了。。。
前端·后端·ai·程序员·大模型·编程
孟祥_成都30 分钟前
nextjs 16 基础完全指南!(一) - 初步安装
前端·next.js
程序员爱钓鱼30 分钟前
使用简单 JSON + 自定义 t 函数实现轻量多语言国际化(无需 next-intl)
前端·javascript·trae
一 乐42 分钟前
助农平台|基于SprinBoot+vue的助农服务系统(源码+数据库+文档)
前端·javascript·数据库·vue.js·ecmascript·springboot
vivo互联网技术1 小时前
浅谈 AI 搜索前端打字机效果的实现方案演进
前端·vue·dom
●VON1 小时前
Electron 小游戏实战:太空打砖块(Space Breakout)
前端·javascript·electron
新晨4371 小时前
Vue 3 定时器清理的最佳实践
javascript·vue.js
重铸码农荣光1 小时前
深入理解 JavaScript 原型机制:从“如何拿到小米 SU7”说起
前端·javascript
Zyx20071 小时前
深入 JavaScript 事件机制:从冒泡到事件委托的高效实践
javascript
乐观的用户1 小时前
搞懂虚拟列表实现原理与步骤
前端·vue.js