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

相关推荐
程序员黑豆29 分钟前
鸿蒙应用开发之模拟器安装与使用教程
前端·harmonyos
YIAN32 分钟前
大模型总 "胡说八道"?用 LangChain.js 从零实现 RAG 语义检索系统
javascript·langchain
王莎莎42 分钟前
MCP 解决的是工具接入,科研 Agent 还缺的是科学证据接口标准化
前端·人工智能
zhanghaha13141 小时前
Python语言基础:4_数据类型转换
java·前端·python
kyriewen1 小时前
别再写useMemo了——2026年这5个React性能优化已经是反模式
前端·react.js·ai编程
OpenTiny社区1 小时前
TinyRobot v0.5.0 新版本强在哪?
前端·vue.js·github
奇牙coding2 小时前
gpt-5.6-sol 接入指南:reasoning_effort 参数配置、推理链验证与常见报错排查
前端·css·gpt·ai
sugar__salt2 小时前
Vue.js 前置知识:ES6+ 核心特性完全指南
前端·javascript·vue.js·vue·es6
雪隐2 小时前
个人电脑玩AI-10让5060 Ti给你打工——我让 Claude Code 喝上了本地杂粮:Ternary-Bonsai-27B 部署历险记
前端·人工智能·后端
Bigger2 小时前
我受够了每天问“今天吃什么”,于是做了个 AI 菜单工具
前端·人工智能·agent