2
import {
 Form, Input, Tooltip, Icon
} from 'antd';
 import React , {Component }from 'react';
import ReactDOM from 'react-dom';

export default class RegistrationForm extends Component {
     state = {
     confirmDirty: false,
     autoCompleteResult: [],
     };

     handleSubmit = (e) => {
         e.preventDefault();
         this.props.form.validateFieldsAndScroll((err, values) => {
         if (!err) {
            console.log('Received values of form: ', values);
          }
       });
       }

     handleConfirmBlur = (e) => {
         const value = e.target.value;
         this.setState({ confirmDirty: this.state.confirmDirty || !!value                
         });
         }

        render() {
           console.log(this.props.form)
             const { getFieldDecorator } = this.props.form;

             const formItemLayout = {
             labelCol: {
                   xs: { span: 24 },
                   sm: { span: 8 },
                 },
              wrapperCol: {
                  xs: { span: 24 },
                  sm: { span: 16 },
              },
             };

return (
  <Form {...formItemLayout} onSubmit={this.handleSubmit}>
    <Form.Item
      label="E-mail"
      >
      {getFieldDecorator('email', {
        rules: [{
          type: 'email', message: 'The input is not valid E-mail!',
        }, {
          required: true, message: 'Please input your E-mail!',
        }],
      })(
        <Input />
        )}
    </Form.Item>

    <Form.Item
      label={(
        <span>
          Nickname&nbsp;
          <Tooltip title="What do you want others to call you?">
            <Icon type="question-circle-o" />
          </Tooltip>
        </span>
      )}
      >
      {getFieldDecorator('nickname', {
        rules: [{ required: true, message: 'Please input your nickname!', whitespace: true }],
      })(
        <Input />
        )}
    </Form.Item>
  </Form>
);
  }
   }

我正在使用ant design,但是当我运行这段代码时,它说this.props.form is undefinedgetFieldDecorator当我在render函数中声明时,在这一行中。

请问这些道具是从哪里来的,怎么用?我没有任何传递任何prop. 帮助修复它。提前致谢。

4

3 回答 3

3

请像这样导出您的组件

export default Form.create()(RegistrationForm)
于 2019-03-12T02:53:59.627 回答
1

你应该像这样导出一个类:

export default Form.create()(RegistrationForm)

表单对象将通过这种方式注入到道具中。

于 2019-03-12T02:35:43.130 回答
1

我用这种方式

const WerappedRegistration = Form.create({ name: 'registrationform' })(RegistrationForm);
export default WerappedRegistration;
于 2019-06-20T06:36:57.540 回答