React-Upload在Form表單中報錯[antd: Upload] `value` is not a valid prop, do you mean `fileList`


錯誤:Warning: [antd: Upload] value is not a valid prop, do you mean fileList?

然后在Form.Item加上valuePropName="fileList"屬性后,初始化組件正常,但是點擊上傳文件就會報錯item.map is not a function , 出現了空指針錯誤

則需要在Form.Item中加上getValueFromEvent={normFile}

const normFile = (e) => {  //如果是typescript, 那么參數寫成 e: any
  console.log('Upload event:', e);
  if (Array.isArray(e)) {
    return e;
  }
  return e && e.fileList;
};

參考官方文檔:https://ant.design/components/form-cn/#API


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM