很难传递一些数据来表达。我正在尝试发送从表单中收集的一些数据。表单值正在正确更新。但是当我到达终点时,我不知道如何注销我正在传递的内容。任何指针将不胜感激。
表达:
app.post('/something-to-post', cors(corsOptionsDelegate), (req, res)=> {
//how do I log what I am passing from the form
console.log('full name:', req.data);
});
反应
import React, {useState} from "react";
import axios from "axios";
const Form = () => {
const [fullName, setFullName] = useState('');
function handleInputChange(event) {
setFullName(event.target.value); // updates state properly
}
function post(event){
event.preventDefault();
console.log('full name:', fullName); // logs out correctly
axios.post('http://localhost:9000/something-to-post', {name: fullName})
.then(response => {
// todo
})
.catch(error => {
// todo
})
}
}
return (
<form onSubmit={post}>
<input type="text" value={fullName} onChange={handleInputChange}/>
<button type="submit">Submit</button>
</form>
)
};
export default Form;