class Child2 extends Component{ constructor(props) { super(props); console.log(1, "初始化组件"); this.state = { count:1 } } static getDerivedStateFromProps(props, state) { console.log(2,"将props中的数据映射到state中"); return props;//返回值 ,是根据props 要映射到state中的值 } componentDidMount() { console.log(4, "组件挂载完成"); //处理副作用(Dom-操作,数据请求) } render() { console.log(3,"构建虚拟dom"); console.log(this.state); const { count,parentInfo} = this.state; return <> <p>count:{count}------parentInfo:{ parentInfo}</p> </> } }