小编Mar*_*edo的帖子

使用扩展的React.Component机制正确创建一个antd表单

我试图在https://github.com/ant-design/ant-design/blob/master/components/form/demo/horizo​​ntal-login.md中重现antd Form示例

用扩展React.Component替换React.createClass但是我得到一个Uncaught TypeError:无法读取未定义的属性'getFieldDecorator'

使用以下代码:

import { Form, Icon, Input, Button } from 'antd';
const FormItem = Form.Item;

export default class HorizontalLoginForm extends React.Component {
    constructor(props) {
        super(props);
    }

  handleSubmit(e) {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values);
      }
    });
  },
  render() {
    const { getFieldDecorator } = this.props.form;
    return (
      <Form inline onSubmit={this.handleSubmit}>
        <FormItem>
          {getFieldDecorator('userName', {
            rules: [{ required: true, message: 'Please input your username!' }],
          })(
            <Input addonBefore={<Icon type="user" …
Run Code Online (Sandbox Code Playgroud)

reactjs antd

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

antd ×1

reactjs ×1