likes
comments
collection

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

作者站长头像
站长
· 阅读数 807

最近我在使用React+antd重写博客网站,在编写一个表单页面时遇到了如下报错:Warning: [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`?

在查找后解决方法如下:

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

报错是因为Upload组件被嵌套在表单中造成的只需要在对应的Form.Item组件上添加 valuePropName="fileList" 属性就可以了

但是虽然解决了初始化后报错问题,但是在上传图片时会出现新的报错,这是我们需要在添加一个属性:

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

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

getValueFromEvent={normFile}

主要就是处理上传时的状态使展示上传后的预览图片能顺利进行