React之Components

2017-07-21  本文已影响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 组件实例属性

上一篇下一篇

猜你喜欢

热点阅读