Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.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
Javascript Reactjs中的maxLength_Javascript_Reactjs - Fatal编程技术网

Javascript Reactjs中的maxLength

Javascript Reactjs中的maxLength,javascript,reactjs,Javascript,Reactjs,假设以下代码: 类按钮扩展了React.Component{ 渲染{ 回来 this.props.handleInputthis.props.value} value={this.props.value}> {this.props.value} } } 类TodoApp扩展了React.Component{ 构造器{ 超级作物 此.state={ 输入: } this.handleInput=this.handleInput.bindthis; this.handleInputChange=th

假设以下代码: 类按钮扩展了React.Component{ 渲染{ 回来 this.props.handleInputthis.props.value} value={this.props.value}> {this.props.value} } } 类TodoApp扩展了React.Component{ 构造器{ 超级作物 此.state={ 输入: } this.handleInput=this.handleInput.bindthis; this.handleInputChange=this.handleInputChange.bindthis; } handleInputvalue{ this.setState=>{ 输入:state.input+=值 } } handleInputChangeevent{ const{value,maxLength}=event.target; const limitedMessage=value.slice0,maxLength 这是我的国家{ 输入:limitedMessage } } 渲染{ 回来 } }
ReactDOM.render、document.querySelectorapp您还应该像处理handleInputChange一样处理handleInput中文本的最大长度

handleInputvalue{ 设{input}=this.state; 输入+=值 this.setStatestate=>{ 输入:input.0,3 }
} 因为在这个函数中:

handleInput(value){
  this.setState( state => ({
    input: state.input += value
  }))
}

您忘了检查maxLength,因此它会将值附加到state.input中。在任何情况下

是的,我现在明白了。谢谢@rtlatelpa4很乐意提供帮助: