Reactjs 使用默认列表响应antd上传所需输入错误

Reactjs 使用默认列表响应antd上传所需输入错误,reactjs,antd,Reactjs,Antd,我在我的应用程序上使用antdUI框架。此外,我还有表单,其中包含所需的上传图像字段。有时此字段具有defaulList。问题是,当定义了defaultList时,仍然无法通过验证 上传道具: const uploadProps = { name: 'file', action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76', headers: { authorization: 'authorizatio

我在我的应用程序上使用
antd
UI框架。此外,我还有
表单
,其中包含所需的
上传
图像字段。有时此字段具有
defaulList
。问题是,当定义了
defaultList
时,仍然无法通过验证

上传
道具:

const uploadProps = {
    name: 'file',
    action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
    headers: {
      authorization: 'authorization-text',
    },
    onChange(info) {
      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList)
      }
      if (info.file.status === 'done') {
        message.success(`${info.file.name} file uploaded successfully`)
      } else if (info.file.status === 'error') {
        message.error(`${info.file.name} file upload failed.`)
      }
    },
    defaultFileList: [
      {
        uid: '1',
        name: 'xxx.png',
        status: 'done',
        response: 'Server Error 500', // custom error message to show
        url: 'http://www.baidu.com/xxx.png',
      },
  }
输入:

 {formItem(
   props.form.getFieldDecorator('Image', {
     rules: [{ required: true }],
       })(
         <Upload {...uploadProps}>
           <Button>
             <Icon type="upload" /> Click to Upload
           </Button>
         </Upload>,
        ),
        {
          label: 'Image',
        },
      )}
{formItem(
props.form.getFieldDecorator('Image'{
规则:[{required:true}],
})(
点击上传
,
),
{
标签:“图像”,
},
)}
submit
之后,我得到一个验证错误


您不应该将
defaultFileList
getFieldDecorator
一起使用

Antd
抛出有关此的警告

警告:
defaultFileList
对于将设置的
getFieldDecorator
无效
文件列表
,请改用
选项。初始值

将defaultFileList数组移动到getFieldDecorator选项的initialValue字段

 {formItem(
   props.form.getFieldDecorator('Image', {
     rules: [{ required: true }],
     initialValue: [
      {
        uid: '1',
        name: 'xxx.png',
        status: 'done',
        response: 'Server Error 500', // custom error message to show
        url: 'http://www.baidu.com/xxx.png',
      },
      ]
       })(
         <Upload {...uploadProps}>
           <Button>
             <Icon type="upload" /> Click to Upload
           </Button>
         </Upload>,
        ),
        {
          label: 'Image',
        },
      )}
{formItem(
props.form.getFieldDecorator('Image'{
规则:[{required:true}],
初始值:[
{
uid:'1',
名称:“xxx.png”,
状态:“完成”,
响应:“服务器错误500”,//要显示的自定义错误消息
网址:'http://www.baidu.com/xxx.png',
},
]
})(
点击上传
,
),
{
标签:“图像”,
},
)}