我有一個登錄表單,按鈕點擊資料應該發送到后端。我使用 ant design 和 Form action 屬性,我正在傳遞(action={url})將發送資料的服務 url。但是,當我單擊提交按鈕時,沒有任何反應。我嘗試將 antd 表單更改為使用帶有 antd 表單控制器的 html 表單,例如 Form.Item 和 Input 組件,并提交資料。我懷疑問題出在 antd action屬性中。如何使用 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>
uj5u.com熱心網友回復:
您應該handleSubmit使用Fetch API或axios 之類的 HTTP 客戶端(推薦)在函式內部發送請求。axios 的一個例子:
const handleSubmit = (values) => {
axios.post(url,values).then((response) => {
console.log(response);
}).catch((error) => {
console.log(error);
})
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/495410.html
