美文网首页
React之Components

React之Components

作者: 卖梦想的男孩 | 来源:发表于2017-07-21 17:15 被阅读14次

    Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. React.Component
    is provided by React
    .

    Components主要是用React来开发相互独立UI控件的规范,或者说是模板也行,是React组件开发的使用最频繁的组件。

    1. 一个简单的栗子🌰

    class Greeting extends React.Component {
      render() {
        return <h1>Hello, {this.props.name}</h1>;
      }
    }
    

    2. 生命周期

    1 组件加载

    2 组件渲染
    React中通过props和state来控制渲染的内容,所以以下方法中可以通过对props和state作监控或处理来影响渲染。

    3 组件卸载
    当组件需要对脱离后的组件做部分资源释放,需要考虑该部分

    4 组件更新

    5 组件类属性

    6 组件实例属性

    • props

      主要是用来接收外来属性
    • state

      主要是用来自身UI更新

    相关文章

      网友评论

          本文标题:React之Components

          本文链接:https://www.haomeiwen.com/subject/capekxtx.html