1. 程式人生 > >Ant Design中的Form元件

Ant Design中的Form元件

1. 使用Form.create()包裹過的元件可以獲取到this.props.form屬性

Form.create()(Comp)

 

2. getFieldDecorator()

 1 // 在表單中的使用
 2 <FormItem>
 3    {
 4      getFieldDecorator('field', {
 5        rules: [{}],
 6        // ...
 7      })(
 8        // 相關form元件
 9     )
10   }
11 </FormItem>

 

3. getFieldsValue()

render() {
  const { getFieldsValue } = this.props.form
  // 獲取全部表單項的value
  const allValue = getFieldsValue()
  // 獲取field與查詢值相匹配表單項的value
  const spcValue = getFieldsValue(['field1', 'field2', '...'])
}