react中通过createRef获取video元素,第一次打印出来为null?

新手上路,请多包涵

export default class TrailResult extends Component {
constructor() {

super()
this.video = React.createRef()

}
}

showVideo = () => {
const video = this.video.current
console.log(this.video)
}

render() {
return(
<video ref={this.video} style={{ width: '600px' }}>
视频测试
</video>)
}

抱歉,第一次提问,代码格式好像不知道怎么调...先试一下

阅读 2.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题