1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| handleSubmit(e) { e.preventDefault();
const { name, password, department, gender } = this.state; fetch('http://localhost:8080/api/user', { mode: "cors", method: 'POST', body: JSON.stringify({ name, password, department, gender }), headers: { "Content-Type": "application/x-www-form-urlencoded", } }) .then((res) => res.json()) .then((res) => { if (res.id) { alert('添加用户成功'); this.setState({ name: '', password: 0, gender: '' }); } else { alert('添加失败'); } }) .catch((err) => console.error(err)); }
|