下载文件后wx.openDocument预览模拟器可以,在手机上没有反应?
发布于 4 年前 作者 chaoyuan 3949 次浏览 来自 官方Issues

使用 wx.downloadFile 下载文件后 使用wx.openDocument 预览时 在开发工具模拟器中没有问题   在手机中无反应  文件问excel  模拟器预览是直接打开wps   在手机点击后无反应  应该怎么做

<button catchtap="get">get</button>
get: function() {
   wx.downloadFile({
     url: 'https://aksoapplet.oss-cn-hangzhou.aliyuncs.com/excel/20190731/84c40a1d7e27466fa6d34f4168a14289.xlsx',
     success(res) {
       if (res.statusCode === 200) {
         const filePath = res.tempFilePath;
         console.log(filePath);
         // var fileType = "";
         // let dIndex = filePath.lastIndexOf(".");
         // fileType = filePath.substring(dIndex + 1, filePath.length);
         // if (fileType == "jpeg") {
         //   fileType = "xlsx"
         // }
         // console.log("fileType-->", fileType);
         //打开文件
 
         wx.openDocument({
           filePath: filePath,
           fileType: 'xlsx',
           success(res) {
             console.log('文件打开');
           },
           fail(res) {
             console.log(res)
           }
         })
       }
     }
   })
 },

求教怎么在真机下载并预览文件  文件为excel

1 回复

downloadFile的域名需要配置好

回到顶部