父组件:
import React from 'react'
import Child from './components/Child'
export default class Demo extends React.Component{
state={
info:{} //传递给子组件
}
saveList(list){
//子组件传来的数据
console.log(list)
}
render(){
<div>
<Child info={this.state.info} saveList={this.saveList}/>
</div>
}
}
子组件:
import React from 'react'
export default class Child extends React.Component{
state={
list:[]
}
const toFather = ()=>{
this.props.saveList(this.state.list) //传递给父组件数据
}
render(){
console.log(this.props.list) //获取父组件传递的数据
return <div>子组件</div>
}
}