search

Home  >  Q&A  >  body text

javascript - About how to use arrow functions to define functions in react

Go directly to the code
The following is the code of login.jsx

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

<code>import React from 'react';

import ReactDOM from 'react-dom';

import {

    render

} from 'react-dom';

import {

    Form,

    Icon,

    Input,

    Button,

    Checkbox

} from 'antd';

 

const FormItem = Form.Item;

 

class LoginForm extends React.Component {

    // constructor(props) {

    //     super(props);

    //     this.loginSubmit = this.loginSubmit.bind(this);

    // };

    loginSubmit = (e) => {

        e.preventDefault();

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

            if (!err) {

                console.log('Received values of form: ', values);

            }else{

 

            }

        });

    }

    render() {

        const {

            getFieldDecorator

        } = this.props.form;

        return (

            <Form className="login-form" onSubmit={this.loginSubmit}>

                <FormItem>

                    {

                        getFieldDecorator('sss', {

                                rules: [{ required: true, message: 'Please input your username!' }],

                            }

                        )

                        (

                            <Input prefix={<Icon type="user" style={{ fontSize: 13 }} />} placeholder="Username" />

                        )

                    }

                </FormItem>

                <FormItem>

                    {getFieldDecorator('password', {

                        rules: [{ required: true, message: 'Please input your Password!' }],

                    })(

                        <Input prefix={<Icon type="lock" style={{ fontSize: 13 }} />} 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>

                    <p>

                        <Button type="primary" htmlType="submit" className="login-form-button">

                            Log in

                        </Button>

                        Or <a href="">register now!</a>

                    </p>

                     

                </FormItem>

            </Form>

        );

    }

}

const Login = Form.create()(LoginForm);

export default Login;</code>

After saving, the browser will open and an error will be reported directly. I checked that react and antd are both written in this way. The specific error is as follows:

Please give me some advice

某草草某草草2863 days ago787

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-05-19 10:10:59

    You are missing this babel-preset-stage

    reply
    0
  • Cancelreply