getFieldValue取得值为undefined

代码如下:

import { Form, Input, Button} from 'antd';

const FormItem = Form.Item; 

class PCHeader extends React.Component { 

  handleSubmit(e){  
    e.preventDefault(); 
    var formData = this.props.form.form.getFieldsValue();
    console.log(formData);
    };


      let {getFieldProps} = this.props.form;

      return(

      
this.handleSubmit.bind(this)}> "账户"> { "请输入您的账号" {...getFieldProps('r_userName')}/> } type="password" label="密码"> { "请输入您的密码" {...getFieldProps('r_password')}/> } type="password" label="确认密码"> { "请再次输入你的密码" {...getFieldProps('r_confirmPassword')}/> } ); }; }

但是用getFieldValue取得值为undefined
后来在官网上找到结局方案,修改部分代码如下:

 this.props.form.validateFields((err, values) => {

      if (!err) {
        console.log('Received values of form: ', values);
      }else{
        //处理错误
        console.log(err);
      }

    });

你可能感兴趣的:(react)