20200129-React基础-高级应用
一、组合与继承 概念:将组件的开标签与闭标签之间的内容展示在组件的内部进行展示,通过prop传递。(父组件中定义子组件的内容,类似于vue中的插槽slot) 形式 包含关系 渲染其他组件 //父组件 import ChildA from './childA.jsx' class Father extends Component { state = {} render(){ let Acom = <a href="#">这是一个a标签组件</a> return <div className="extend-father" style={{border:'1px solid #000'}}> father content <ChildA Acom={Acom}> <h1>包含关系:嵌入内容</h1> </ChildA> </div> } } // 子组件 class ChildA extends Component { constructor(props){ super(props) this.state = {} } render(){ return <div style={{backgroundColor:'orange'}}> hello world! {/* 包含关系 */} {this.props.children} {/* 渲染其他组件 */} {this.props