首先说一下需求,三个input框的值输入数字,想让其自动加减,然后复制给第四个输入框
很简单的一个例子,原本想用onChange结合getFieldValue来使用呢 却发现此onChange非彼onChange的
html代码
1 <Row type={'flex'} style={{ width: '100%' }} align="middle"> 2 <Col span={17}> 3 <FormItem label="一号" 4 style={{ display: 'flex' }} 5 {...formItemLayout} 6 required={true} 7 > 8 {form.getFieldDecorator('one', config)( 9 <Input placeholder="one" onChange={onChange} /> 10 )} 11 </FormItem> 12 </Col> 13 </Row> 14 <Row type={'flex'} style={{ width: '100%' }} align="middle"> 15 <Col span={17}> 16 <FormItem label="二号" 17 style={{ display: 'flex' }} 18 {...formItemLayout} 19 required={true} 20 > 21 {form.getFieldDecorator('two', config)( 22 <Input placeholder="two" onChange={onChange}/> 23 )} 24 </FormItem> 25 </Col> 26 </Row> 27 <Row type={'flex'} style={{ width: '100%' }} align="middle"> 28 <Col span={17}> 29 <FormItem label="三号" 30 style={{ display: 'flex' }} 31 {...formItemLayout} 32 required={true} 33 > 34 {form.getFieldDecorator('three', config)( 35 <InputNumber placeholder="three" onChange={onChange} /> 36 )} 37 </FormItem> 38 </Col> 39 </Row> 40 <Row type={'flex'} style={{ width: '100%' }} align="middle"> 41 <Col span={17}> 42 <FormItem label="总数" 43 style={{ display: 'flex' }} 44 {...formItemLayout} 45 required={true} 46 > 47 {form.getFieldDecorator('sum', config)( 48 <Input placeholder="sum" /> 49 )} 50 </FormItem> 51 </Col> 52 </Row>