next.js 正在将循环结构转换为JSON -->从具有构造函数'HTMLInputElement'的对象开始

2lpgd968  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(159)

我已经阅读了几个解决方案在这里大约相同,但似乎仍然不能得到通过这个错误。我使用axios作为我的http客户端和应用程序是一个nextjs应用程序

  1. import React, {useState} from 'react'
  2. import axios from 'axios'
  3. export default function Home() {
  4. const [username, setUsername] = useState("")
  5. const [password, setPassword] = useState("")
  6. const handleSubmit = async (e) => {
  7. e.preventDefault()
  8. const credentials ={username: username, password: password}
  9. const user = await axios.post('/api/auth/login', credentials);
  10. }
  11. return (
  12. <div>
  13. <form onSubmit={e => handleSubmit(e)}>
  14. <label htmlFor='username'>Username</label>
  15. <input type="text" name="username" id="username" onChange={e=> setUsername(e.target)} />
  16. <label htmlFor='password'>Password</label>
  17. <input type="password" name="password" id="password" onChange={e=> setPassword(e.target)} />
  18. <button>Login</button>
  19. </form>
  20. </div>
  21. )
  22. }
des4xlb0

des4xlb01#

需要从事件输入值。不是整个目标

  1. setUsername(e.target.value)
  2. setPassword(e.target.value)

此外,将value添加到输入

  1. <input value={username} ...

相关问题