zoukankan      html  css  js  c++  java
  • react定义渲染组件

    定义方式:

     1、工厂函数组件 (简单组件)

      (1)、定义组件

      function MyComponent() {

        reutrn <h2>工厂函数组件(简单组件)</h2>

      }

      (2)、渲染组件

      ReactDOM.render(<MyComponent />, document.getElementById('标签id'))

     2、ES6类组件 (复杂组件)

      (1)、定义组件

      class MyComponent2 extends React.Component {  // 在react里有一个属性是Component类

        render() {

          return <h2>ES6类组件 (复杂组件)</h2>

        }

      }

      先创建实例 MyComponent2 再调用 render() 方法

      (2)、渲染组件

      ReactDOM.render(MyComponent2 />, document.getElementById('标签id'))

    组件三大属性:

     1、state

      state是组件对象最重要的属性,值是 对象 (可以包含多个数据),通过更新组建的state来更新对应的页面显示内容(即重新渲染)

     2、props

     3、refs与事件处理

  • 相关阅读:
    Lucky Coins Sequence
    A == B ?
    Chinese Rings
    51nod 1051 最大子矩阵和
    51nod 1103 N的倍数
    Codeforces Round #429 (Div. 2)
    51nod 1043 幸运号码(数位dp
    51nod 1266 蚂蚁
    51nod 1090 3个数和为0
    51nod 1082 与7无关的数
  • 原文地址:https://www.cnblogs.com/Z_66/p/15088573.html
Copyright © 2011-2022 走看看