未触发的ANTD形式或动作属性
我有一个登录表单,该表格单击数据应将数据发送到后端。我使用ANT设计和表单操作属性,我正在传递服务URL (action = {url})
将发送数据的位置。但是,当我单击“提交”按钮时,什么也不会发生。我尝试将ANTD表单与ANTD表单控制器(例如Form.Sorm.Item和Input组件)更改为使用HTML表单,并提交数据。我怀疑问题在ANTD Action 属性中。如何使用操作属性制作ANTD表单以提交数据?
const handleSubmit = (val) => {
console.log("Values : ", val);
};
<Form
name="login"
layout="vertical"
autoComplete="off"
action={url}
method="post"
onFinish={handleSubmit}
>
<Form.Item
htmlFor="username"
label="Username"
name="username"
rules={[
{
required: true,
message: `Please input your username!`,
},
]}
>
<Input/>
</Form.Item>
<Form.Item
htmlFor="password"
label="Password"
name="password"
rules={[
{
required: true,
message: `Please input your password!`,
},
]}
>
<Input.Password/>
</Form.Item>
<Button
size="large"
htmlType="submit"
name="login"
id="login-btn"
>
Login
</Button>
</Form>
I have a login form where on button click data should be sent to the backend. I use ant design and on Form action attribute I am passing the service url (action={url})
where the data will be sent. However, when I click the submit button, nothing happens. I tried changing the antd form to use html form with antd form controllers, like Form.Item and Input components and the data get submitted. I suspect that the problem is within antd action attribute. How can I make an antD Form to submit the data using the action attribute?
const handleSubmit = (val) => {
console.log("Values : ", val);
};
<Form
name="login"
layout="vertical"
autoComplete="off"
action={url}
method="post"
onFinish={handleSubmit}
>
<Form.Item
htmlFor="username"
label="Username"
name="username"
rules={[
{
required: true,
message: `Please input your username!`,
},
]}
>
<Input/>
</Form.Item>
<Form.Item
htmlFor="password"
label="Password"
name="password"
rules={[
{
required: true,
message: `Please input your password!`,
},
]}
>
<Input.Password/>
</Form.Item>
<Button
size="large"
htmlType="submit"
name="login"
id="login-btn"
>
Login
</Button>
</Form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在
handlesubmit
函数内发送请求,并使用 fetch api 或http客户端,例如 axios (推荐)。Axios的一个例子:
You should send the request inside your
handleSubmit
function using Fetch API or an HTTP client like axios (recommended).An example with axios: