react input 自动聚焦 function_module 2021-12-22 729 阅读1分钟 关键词:react js input focus componentDidMount() { // 使用setTimeout可以有效避免页面刷新导致的聚焦无效 setTimeout(() => { this.refs.myInput.focus() },100) } <input type="search" placeholder="搜索" ref="myInput" // 关联 onChange={this.onChange} />