react如何实现父组件调用子组件函数,下面web建站小编给大家详细介绍一下实现代码!
实现代码如下:
class father extends Component {
constructer(props) {
super(props);
this.state={
a: '1',
b: '2',
}
this.myRef
this.test = this.test.bind(this)
}
hange() {
const { a,b } = this.state
console.log(this.myRef.test(a,b)) // 直接调用实例化后的Children组件对象里函数
}
render() {
<Children wrappedComponentRef={(inst) => { this.myRef = inst } } ref={(inst) => { this.myRef = inst } } />
<button onClick={this.test}>点击</button>
}
}
ps:wrappedComponentRef是react-router v4中用来解决高阶组件无法正确获取到ref。
上面是“react如何实现父组件调用子组件函数”的全面内容,想了解更多关于 reactjs 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2755.html
workflows工作流
雪地里一只可爱的小老虎
一个熙熙攘攘的市场场景,里面摆满了南瓜
一个精致透明的朱红色水晶凤凰
一个极其美丽细致的女孩ComfyUI工作流
星空星域星球comfyui工作流
穿着蘑菇帽的小蚂蚁探险家ComfyUI工作流
乒乓卡通3d人物
严寒的冬天里一只小鸟在森林的树枝上休息
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

用ascii字符画图像
HTML5 Canvas 刻度尺
如何利用css3+js做一个下雨效果
jquery鼠标滑过图片边框特效(jquery.focus-follow插件)
js导出excel插件(兼容mac电脑Numbers表格)
js+css3做一个灯泡开灯关灯效果
纯CSS饼图效果









