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, react-router, 子组件, 父组件
上面是“react如何实现父组件调用子组件函数”的全面内容,想了解更多关于 reactjs 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2755.html
workflows工作流
奇幻绘画风格:一只巨大蜗牛ComfyUI工作流
水中一台精致而破旧的老式电视鱼缸ComfyUI工作流
一条赤壁龙从蛋中孵化出来ComfyUI工作流
一艘来自工业时代的飞船ComfyUI工作流
一条色彩斑斓的超现实小孔雀鱼ComfyUI工作流
一座千年九尾白狐玉雕ComfyUI工作流
一个闪闪发光的金属球ComfyUI工作流
一张科幻照片,火星车在沙漠里ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!