首页 > 其他分享 >react在组件中获取 dom

react在组件中获取 dom

时间:2022-11-25 11:00:26浏览次数:34  
标签:React dom inputRef react props 组件 createRef

  • 使用 16 版本后的 createRef()函数
  • class MyComponent extends React.Component<iProps, iState> {
  • constructor(props) {
  • super(props);
  • this.inputRef = React.createRef();
  • }
  • render() {
  • return <input type="text" ref={this.inputRef} />;
  • }
  • componentDidMount() {
  • this.inputRef.current.focus();
  • }
  • }
     

标签:React,dom,inputRef,react,props,组件,createRef
From: https://www.cnblogs.com/zwjun/p/16924461.html

相关文章