未捕获的类型错误:无法读取未定义的属性(读取“原型”)

问题描述 投票:0回答:1

最近编码的时候,突然无缘无故的报错。在寻找解决该问题的方法之后,我输入了一些代码,现在,我得到了一个全新的代码。前端工作在vite上,是用javascript编写的。

The first error

The second error

import { useState } from 'react'
import './App.css'
import { response } from 'express'

function App() {
  const [Password, SetPassword] = useState('')
  const [Username, SetUsername] = useState('')

  const onSubmit = () => {
  fetch('http://localhost:3000', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      Username: Username, // No need to wrap Username in an object
      Password: Password
    })
  })
  .then(response => {
    if (response.status == 200){
      alert('Matched!')
    }
  })
  .catch(error => {
    console.error(response)
    })
  }
  return (
    <>
      <div class='mainDiv  --centered'>

      <input class='UsernameBox --verticallycentered' placeholder='Username/Email/Phone' value={Username} onChange={(e) => SetUsername(e.target.value)}></input>
      

      <input class='PasswordBox --verticallycentered' placeholder='Password' value={Password} onChange={(e) => SetPassword(e.target.value)}></input>
      <h4 className='ErrorThingy'>Passwords can only contain Letters, numbers and symbols</h4>
      <button onClick={onSubmit} className='LoginBtn --centered'> Log in</button>
      </div>
    </>
  )
}

export default App

javascript reactjs vite
1个回答
1
投票

这是因为您正在将express导入到客户端应用程序中。

© www.soinside.com 2019 - 2024. All rights reserved.