class Com extends React.Component{
constructor(props){
super(props)
this.myRef=React.createRef(); //React.createRef()定义ref接收
}
fun=()=>{
console.log(this.myRef.current.value) //输出在对应DOM中接收到的数据
}
render(){
return(
<div>
<input type="text" ref={this.myRef} placeholder="请输入"/>
<button onClick={this.fun}>获取收入内容</button>
</div>
)
}
}
ReactDOM.render(<Com />,document.getElementById("demoReact"));