import React from 'react'
class App extends React.Component {
  private readonly myRef: React.RefObject<HTMLDivElement>
  constructor (props: any) {
    super(props)
    this.myRef = React.createRef() // 1.创建一个ref的引用,并且可以通过this.myRef属性去进行访问
    this.state = {
    }
  }
  componentDidMount () {
    // 可以通过this.getRef.current  属性名来进行获取
    console.log(this)
  }
  render () {
    return (
      <div ref={this.myRef}>
        <h1>234234324</h1>
      </div>
    )
  }
}
export default App
 
版权声明:本文为Yi_Li_Tong_Wan_DOU原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
