React 父组件如何获取子组件的ref值?

React 父组件如何获取子组件的ref值?
父组件:

const registerStepTwo = React.createClass({    handleChange:function(){        
var confirmPassText =  this.refs.confirmPassText.value;        console.log(confirmPassText)//子组件ref的值取不到
    },
    render(){        return(            <div>
                {navBar}                <div className="list-ul">
                    <ul>
                        <ConfirmPass  ref="confirmPassText" onChange={this.props.handleChange}  />
                    </ul>
                </div>
            </div>
        )
    }
})

子组件:

   const ConfirmPass = React.createClass({
        render(){       
            return(                <div>
                    <li>
                        <div className="registerLeft">
                        <input ref="confirmPassText" type="password"  onChange={this.handleChange}   
                        className="loginText" />
                        </div>
                    </li>
                </div>
            )
        }
    })


月关宝盒
浏览 4059回答 1
1回答

茅侃侃

this.props.handleChange改成this.handleChange。handleChange是你这个组件的函数,不是传进来的属性。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript