chooseFile:fail 文件選擇器對(duì)話框只能在用戶激活時(shí)顯示

復(fù)現(xiàn):選擇文件上傳在本地的時(shí)候都好使,但是通過(guò)hbuilderx打包上測(cè)試環(huán)境之后,ios端會(huì)出現(xiàn)這種問(wèn)題


chooseFile:fail

原選取文件上傳方法 例子

 // 上傳文件的測(cè)試
async uploadFile() {
  const token = await get(getTokenApi, {})
  uni.chooseFile({
      count: 1,
      extension: ['.zip', '.pdf', '.doc', '.docx', '.xls', '.xlsx'],
      success: function (res)  {
        console.log('chooseFile', res)
        // 上傳文件接口,帶著token
      },
     fail: function (res)  {
        console.log('chooseFile', res)
      }
   });
}

我項(xiàng)目中產(chǎn)生的原因:是 async 把 success: function (res) {} 函數(shù)影響了,在使用uni.chooseFile的時(shí)候,注意,不要在方法中使用 async
改造后的選取文件上傳方法

 // 上傳文件的測(cè)試
uploadFile() {
  get(getTokenApi, {}).then((token) => {
    uni.chooseFile({
      count: 1,
      extension: ['.zip', '.pdf', '.doc', '.docx', '.xls', '.xlsx'],
      success: (res) => {
        console.log('chooseFile', res)
        // 上傳文件接口,帶著token
      },
     fail: (res) => {
        console.log('chooseFile', res)
      }
   });
}).catch(() => {}) 
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容