AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
在upload中文件上传到后台,返回文件链接地址,但是在接受到地址之后,更新state组件没有响应更新。 对于受控模式,你应该在`onChange`中始终 setState`fileList`,保证所有状态同步到 Upload 内。类似这里的写法:[http://ant.design/components/upload/#components-upload-demo-fileList](http://ant.design/components/upload/#components-upload-demo-fileList) ~~~js // good onFileChange(fileList) { if ( ... ) { ... } else { ... } // always setState this.setState({ fileList: [...fileList] }); } ... <Upload fileList={this.state.fileList} onChange={this.onFileChange} /> ~~~ ~~~js // bad onFileChange(fileList) { if ( ... ) { this.setState({ fileList: [...fileList] }); } else { ... } } ... <Upload fileList={this.state.fileList} onChange={this.onFileChange} /> ~~~ 在 React.PureComponent 里面还是有问题的 因为React.PureComponent里面做了一层优化判断,filelist有缓存引用, 认为是同一个对象就不会更新, 在React.PureComponent立马 应该生成一个新的对象 handleChange = ({ fileList }) => { // fixed bug this.setState({ fileList: fileList.slice() }); }