微信小程序使用downloadFile自定义文档名称

391 阅读1分钟
     wx.downloadFile({
         url: that.data.url, //pdf链接
    // 链接拼接:wx.env.USER_DATA_PATH + '/'  注意链接拼接  
    //自定义的名称: '检查报告-' + this.data.fileName + '.docx',
    
    filePath: wx.env.USER_DATA_PATH + '/' + '检查报告-' + this.data.fileName + '.docx',
       success(res) {
      //注意修改打开地址filePath
      wx.openDocument({ //打开文档
        filePath: res.filePath,
        fileType: "docx", //文档类型
        success: function (res) {},//成功后执行
        fail: function (res) {//失败后执行
          wx.showToast({
            icon: "error",
            title: '打开文档失败',
          })
        },
      })
    },
     })

  })