//父组件的值变化(this.props.locationFileList),子组件的fileList 字段也跟着变
//子组件
componentDidMount() {
const { form: { setFieldsValue } } = this.props;
setFieldsValue({ fileList: fileListFun(this.props.locationFileList) });
}
//子组件
componentDidUpdate(prevProps: FormProps) {
const { form: { setFieldsValue } } = this.props;
// 这里用componentDidMount初始化渲染的值 与 父组件更新后的值对比
//不想等,就更新为父组件的值
if (prevProps.locationFileList !== this.props.locationFileList) {
setFieldsValue({ fileList: fileListFun(this.props.locationFileList) });
}
}
子要与父的值保持一样:componentDidMount和componentDidUpdate配合使用
最新推荐文章于 2023-03-24 17:52:52 发布