iOS手机怎么下载文件,现在只能预览?
发布于 5 年前 作者 xiajing 9591 次浏览 来自 官方Issues

现在贴上点击下载按钮的方法,望指点,谢谢

exportMusicExcel() {
   wx.showLoading({
     title: '加载中'
   })
   let urlpath = app.globalData.urlPath;
   let that = this;
   let par = {
     openId: this.data.openId,
     cycle: this.data.cycleChange
   }
   api.exportMusicExcel(par).then(res => {
     console.log(res);
     let urlexcel = urlpath + res.data;
     
     wx.downloadFile({
       url: urlexcel,
       success: function (res) {
         const tempFilePath = res.tempFilePath;
         // 保存文件
         wx.saveFile({
           tempFilePath,
           success: function (res) {
             const savedFilePath = res.savedFilePath;
             // 打开文件
             wx.openDocument({
               filePath: savedFilePath,
               success: function (res) {
                 console.log('打开文档成功')
               },
             });
           },
           fail: function (err) {
             console.log('保存失败:', err)
           }
         });
       },
       fail: function (err) {
         console.log('下载失败:', err);
       },
     })
   })
 },
1 回复

downloadFile 域名需要配置的

回到顶部