我已经阅读了几个解决方案在这里大约相同,但似乎仍然不能得到通过这个错误。我使用axios作为我的http客户端和应用程序是一个nextjs应用程序
import React, {useState} from 'react'
import axios from 'axios'
export default function Home() {
const [username, setUsername] = useState("")
const [password, setPassword] = useState("")
const handleSubmit = async (e) => {
e.preventDefault()
const credentials ={username: username, password: password}
const user = await axios.post('/api/auth/login', credentials);
}
return (
<div>
<form onSubmit={e => handleSubmit(e)}>
<label htmlFor='username'>Username</label>
<input type="text" name="username" id="username" onChange={e=> setUsername(e.target)} />
<label htmlFor='password'>Password</label>
<input type="password" name="password" id="password" onChange={e=> setPassword(e.target)} />
<button>Login</button>
</form>
</div>
)
}
1条答案
按热度按时间des4xlb01#
需要从事件输入值。不是整个目标
此外,将
value
添加到输入