antd upload 组件将上传的文件删除后无法触发表单检验

197 阅读1分钟
const normFile = (e: any) => {
    if (Array.isArray(e)) {
      return e;
    }
    return e && e.fileList;
};

<Form.Item label="" name="files" valuePropName="fileList" getValueFromEvent={normFile} rules={[{ required: true, message: "请上传文件" }]}>
  <Upload multiple={false} maxCount={1} accept='.xls,.xlsx,.csv'>
      <p className="ant-upload-text"><span className="link">点击上传</span></p>
  </Upload>
</Form.Item>

敲重点:(根据以下两个字段查下 antd 官方手册就懂为啥要这样做了)

  1. valuePropsName 字段
  2. getValueFromEvent 字段