react 引用antd的表单组件

/*
 * @Author: Twinkle 
 * @Date: 2018-11-07 11:34:48 
 * @Last Modified by: Twinkle
 * @Last Modified time: 2018-11-07 14:29:15
 */
import React, { Component } from 'react';
import './App.less';
import { Form, Icon, Input, Button, Checkbox } from 'antd';
const FormItem = Form.Item;
class App extends Component {
  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 onSubmit={this.handleSubmit} className="login-form">
        <p>表单登录注册</p>
        <FormItem>
          {getFieldDecorator('userName', {
            rules: [{ required: true, message: 'Please input your username!' }],
          })(
            <Input prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="Username" />
          )}
        </FormItem>
        <FormItem>
          {getFieldDecorator('password', {
            rules: [{ required: true, message: 'Please input your Password!' }],
          })(
            <Input prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} type="password" placeholder="Password" />
          )}
        </FormItem>
        <FormItem>
          {getFieldDecorator('remember', {
            valuePropName: 'checked',
            initialValue: true,
          })(  
            <Checkbox>Remember me</Checkbox>
          )}
          <a className="login-form-forgot" href="" >Forgot password</a>
          <Button type="primary" htmlType="submit" className="login-form-button">
            Log in
          </Button>  
          Or <a href="">register now!</a>
        </FormItem>
      </Form>
    );
  }
}

export default App = Form.create()(App);

猜你喜欢

转载自blog.csdn.net/twinkle_J/article/details/83823516