【React学习】组件的概念

组件的概念

jsx语法

  • 必须闭合
  • 顶层只能有一个标签
  • HTML 原生标签使用小写,自定义的组件标签首字母大写
  • 允许js与jsx混写,{}进入js上下文

组件定义

  • 继承React.Component基类,重写render方法
  • 标签属性传值:this.props
  • 标签内容传值:this.props.children
  • 组件内部状态:this.state

组件生命周期

  • componentDidMount:组件挂载后自动调用
  • componentWillUnmount:组件卸载前自动调用
  • componentDidUpdate:UI 每次更新后调用
原创文章 45 获赞 151 访问量 11万+

猜你喜欢

转载自blog.csdn.net/u010697681/article/details/83145855
今日推荐