react 获取 ref

class Child extends React.Component{
constructor(props){
super(props);
this.myRef=React.createRef();
}
componentDidMount(){
console.log(this.myRef.current);
}
render(){
return <input ref={this.myRef}/>
}
}

第二种方法

<input ref={(input) => {this.textInput = input;}} type="text" />

posted on 2019-03-14 17:42  冰love  阅读(952)  评论(0编辑  收藏  举报

导航