1、父组件向子组件传递参数
class child extends component { componentdidmount(){ let name = this.props.default; console,log(name); } render(){ const { default} = this.props; return ( <input /> ) } }
import react, { component } from 'react'; import child from './child'; class parent extends component { state = { name: 'bob' } render() { return ( <div> <child default={this.state.name} /> </div> ) } }
2、子组件向父组件传递参数
class child extends component { state={ name:'bob' } componentdidmount(){ this.props.toparent(this.state.name); } render(){ return ( <input /> ) } }
import react, { component } from 'react'; import child from './child'; class parent extends component { state = { name:'' } getchildinfo = (name)=>{ this.setstate({name:name}); } render() { return ( <div> <child toparent={this.getchildinfo.bind(this)} /> </div> ) } }
以上这篇基于react组件之间的参数传递(详解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
vue源码实战render.js与$nextTick的异步调用
同事牛逼啊,写了个隐藏 bug,我排查了 3 天才解决问题!
【JavaScript笔记(一)】万丈高楼平地起 - 基本概念篇
网友评论