React表单在没有e.preventDefault()的情况下提交了两次,在使用e.preventDefault()的情况下提交了零次

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

下面的代码将导致2次提交。如果我在表单上添加onSubmit = {e => {e.preventDefault();}},则将有零个提交:

export default function SearchBar() {
  return (
    <div>
      <form
        action={BackEnd_ServerName + "/xyz"}
        method="GET"            
      >
        <input
          type="text"
          placeholder=""
          name="frontEnd_searchBox"
        />
      </form>
    </div>
  );
}
reactjs forms events submit
1个回答
0
投票
export default function SearchBar() {
  return (
    <div>
      <form>
        <input
          type="text"
          placeholder=""
          name="frontEnd_searchBox"
        />
      </form>
    </div>
  );
}
© www.soinside.com 2019 - 2024. All rights reserved.