Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用React输入时提交_Html_Reactjs - Fatal编程技术网

Html 使用React输入时提交

Html 使用React输入时提交,html,reactjs,Html,Reactjs,当用户使用enter时,我正在尝试让我的表单提交。现在它只是刷新并将我带到端点/?。我以前让所有东西都工作过,当时我只是让它在点击下工作 class NavBar extends Component { constructor(props) { super(props); this.state = { term: '' } this.search = this.search.bind(this); t

当用户使用enter时,我正在尝试让我的表单提交。现在它只是刷新并将我带到端点/?。我以前让所有东西都工作过,当时我只是让它在点击下工作

 class NavBar extends Component {
     constructor(props) {
        super(props);
        this.state = {
          term: ''
        }
    this.search = this.search.bind(this);
    this.onChange = this.onChange.bind(this);
}

onChange(e) {
  this.setState({
      term: e.target.value
  });
}

search() {
    event.preventDefault();
    event.stopPropagation();
    this.props.searchrequest(this.state.term);
}

render() {
    return (
                <form onSubmit={this.search}>
                    <input type="text" placeholder="Search" value={this.state.term} onChange={this.onChange}/>
                    <button type="submit" >Search</button>
                </form>
      )}
类导航栏扩展组件{
建造师(道具){
超级(道具);
此.state={
术语:“”
}
this.search=this.search.bind(this);
this.onChange=this.onChange.bind(this);
}
onChange(e){
这是我的国家({
术语:目标值
});
}
搜索(){
event.preventDefault();
event.stopPropagation();
this.props.searchrequest(this.state.term);
}
render(){
返回(
搜寻
)}

在提交事件处理程序中使用event.preventDefault()。在提交事件处理程序中使用event.preventDefault()。在提交事件处理程序中使用event.preventDefault()。在
搜索
函数中缺少
事件
参数。如下使用:

search( event ) {
    event.preventDefault();
    event.stopPropagation();
    this.props.searchrequest(this.state.term);
}

搜索
函数中缺少
事件
参数。请这样使用它:

search( event ) {
    event.preventDefault();
    event.stopPropagation();
    this.props.searchrequest(this.state.term);
}

尝试将事件对象作为this.search中的第一个参数


search(event){event.preventDefault()}

尝试将事件对象作为此.search中的第一个参数

search(event){event.preventDefault()}