解决antd Form表单提交status为canceled

表单提交status为canceled的代码

 <Form onSubmit={this.handleSubmit} className="login-form">
                    <Form.Item>
                        {getFieldDecorator('username', {
                            rules: [{ required: true, message: '请输入账号!' }],
                        })(
                            <Input
                                placeholder="请输入账号"
                            />,
                        )}
                    </Form.Item>
                    <Form.Item>
                        {getFieldDecorator('password', {
                            rules: [{ required: true, message: '请输入密码!' }],
                        })(
                            <Input
                                type="password"
                                placeholder="请输入密码"
                            />,
                        )}
                    </Form.Item>
                    <Form.Item>
                        <Button type="primary" htmlType="submit" style={{background:'#99CC33',width:'100%'}}>
                            登录
                        </Button>
                    </Form.Item>
                </Form>

解决方法:修改表单的默认提交事件,改为button的点击事件

修改之后的代码:

<Form className="login-form">
                    <Form.Item>
                        {getFieldDecorator('username', {
                            rules: [{ required: true, message: '请输入账号!' }],
                        })(
                            <Input
                                placeholder="请输入账号"
                            />,
                        )}
                    </Form.Item>
                    <Form.Item>
                        {getFieldDecorator('password', {
                            rules: [{ required: true, message: '请输入密码!' }],
                        })(
                            <Input
                                type="password"
                                placeholder="请输入密码"
                            />,
                        )}
                    </Form.Item>
                    <Form.Item>
                        <Button type="primary" onClick={this.handleSubmit} style={{background:'#99CC33',width:'100%'}}>
                            登录
                        </Button>
                    </Form.Item>

 


版权声明:本文为weixin_44371012原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。