html52.com
我爱小程序-开发者交流社区

iOS手机怎么下载文件,现在只能预览?

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

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);
       },
     })
   })
 },


网友回复

o0o有脾气的酸奶:

downloadFile 域名需要配置的

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付