【发布时间】:2021-11-22 14:32:37
【问题描述】:
我正在尝试在 reactjs 中使用 formik 创建发布请求。但它在 payload 中占用了 value:,这就是为什么会出现 400 错误。
const handleSubmit = async (values: any) => {
await axios
.post('http://localhost:3000/api/certificates', {
values,
}).then(function (response) {
console.log(response);
}).catch((err) => {
console.log('error in call');
console.log(err);
});
};
它正在生成有效载荷
{
"values": {
"sponser": "Hello",
"startDate": "2021-11-22T13:50:59.073Z",
"endDate": "2021-11-23T13:50:59.000Z",
"phaseOfTrial": "1",
"requestStatus": "DRAFT",
"address": "Hello",
"address2": "Hellpo",
"zipCode": "12345",
"city": "new",
"protoColNo": "12312312",
"molecules": "asdasda",
"unAuthMolecule": "YES",
"noOfSubjects": 5,
"personInCharge": "llasdasdasda",
"country": "asdasdasd",
"comments": "asdasdasdasd",
"attachedFile": "asdasdasd"
}
}
在payload 开头是values:,这是我的API 没想到的。我在做什么错?我怎样才能删除它?
【问题讨论】:
标签: javascript reactjs forms react-hooks formik