小程序openDocument在真机无法打开的问题

openDocument方法有一个参数叫fileType,文档上说的非必填,但是不填部分格式的文件又打不开,如docx,测试过程中,pdf和doc都没问题,就docx打开失败,但是如果填写,就只能打开那一种格式的文件。

处理方法:将文件地址链接后缀名截取下来动态塞进去。

openFile(e) {
  console.log(e);
  uni.showLoading({
    title: '加载中'
  })
  uni.downloadFile({
    url: e.url,
    success: function(res) {
      uni.hideLoading();
      const filePath = res.tempFilePath;
      const index = e.url.lastIndexOf(".");
      const suffix = e.url.substring(index+1);
      uni.openDocument({
        fileType: suffix,
        filePath: filePath,
        success: function(res) {
          console.log('打开文档成功')
        }
      })
    }
  })
}


版权声明:本文为zd1007129657原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。