码迷,mamicode.com
首页 > 其他好文 > 详细

react 获取 ref

时间:2019-03-14 18:33:59      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:ref   super   image   rop   class   tor   div   .com   mount   

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" />

react 获取 ref

标签:ref   super   image   rop   class   tor   div   .com   mount   

原文地址:https://www.cnblogs.com/binglove/p/10531811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!