React Ant Design Upload 组件在Form中使用的警告,如何排除:

警告信息 Warning: [antd: Upload] value is not a valid prop, do you mean fileList?

解决方法:

当您在Form.Item中使用Upload时,可能遇到此类警告,解决该问题只需要在Form.Item组件的属性列表中添加如下两个属性即可:

valuePropName="fileList"
getValueFromEvent={normFile}

具体代码:

const normFile = (e: any) => {
    console.log('Upload event:', e);
    if (Array.isArray(e)) {
        return e;
    }
    return e && e.fileList;
};

<Form.Item
    label="Banner图"
    name="banner"
    valuePropName="fileList"
    getValueFromEvent={normFile}
>
<Upload
    name="bannerUpload"
    >
        <Button icon={<UploadOutlined />}>上传图片</Button>
</Upload>
</Form.Item>

03-05 14:03