美文网首页
react 使用ant框架的Input组件踩坑记录

react 使用ant框架的Input组件踩坑记录

作者: Mrmcling | 来源:发表于2020-08-23 14:56 被阅读0次

问题1:input组件的value属性设置无效
原因:被Form.item修饰的组件的value属性会被form.item的initialValue管理。设置initialValue,需要使用form.setFieldsValue来设置。


批注 2020-08-23 145621.jpg

修改流程
(1)

export default class CreateProject extends React.Component {
    updateFormRef = React.createRef();
........
}

(2)

<Form name="..." ref={this.updateFormRef}>
    <Form.Item
        label="项目名称"
        name="projectname"
        rules={[{ required: true, message: '请输入项目名称' }]}
    >
        <Input />
    </Form.Item>
</Form>

(3)

this.updateFormRef.current.setFieldsValue({
    projectname: 'xxx'
})

相关文章

网友评论

      本文标题:react 使用ant框架的Input组件踩坑记录

      本文链接:https://www.haomeiwen.com/subject/txnijktx.html