码迷,mamicode.com
首页 > 其他好文 > 详细

react中的children使用方法

时间:2018-10-25 14:07:23      阅读:515      评论:0      收藏:0      [点我收藏+]

标签:turn   child   def   end   component   来替   xtend   rop   exp   

使用过vue的小伙伴都知道vue中有个slot,也就是插槽,作用就是占位,那么再react中可以使用children来替代
父组件

render(){
    return( 
        <div>
            <Grid>
                我将被传递到Grid组件中
            </Grid>
        </div>
    )
}

子组件

export default class Grid extends React.Component {
    render() {
      return (
        <div>{this.props.children}</div>
      )
    }
}

这样就能够够实现slot的功能了。

react中的children使用方法

标签:turn   child   def   end   component   来替   xtend   rop   exp   

原文地址:https://www.cnblogs.com/wyangnb/p/9849018.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!