react 的定義元件(了解)

2022-08-09 11:12:12 字數 662 閱讀 5547

react 中定義元件的方法

1. 定義元件 react.createclass()  (被淘汰了)

定義元件中的函式 methods 的中的 this 統統指向 元件

2. 函式定義元件

定義的元件時無狀態的,沒有 state 的狀態,沒有生命週期,就是乙個純粹的靜態頁面,不能訪問 this

3. class 定義元件

class 中的事件函式中的 this 不是指向函式本身,而是 null

class 建立的元件的成員函式需要手動繫結

在建構函式裡面,受到手動繫結,讓事件成員中 函式 this 指向當前元件

class 中,如何修改資料

this.setstate( 就可以了

react 中的 props 屬性

元件標籤上的水星,都會記錄在定義在元件中的乙個 props 的屬性

訪問 props --> this.props.name

props 的值,不能改變,而 state 中的值可以改變

proptypes 和 defaultprops

proptypes 驗證 props 中的資料型別必須合法

defaultprops 設定,props 的初始值

es6 class 類的角度來說,給類新增靜態屬性

類的屬性叫靜態成員

自定義React元件

如果還沒有專案,請看建立umi專案 訪問http localhost 8000實際由src pages index.js渲染,內容為 export default function 使用antd新增乙個輸入框和乙個按鈕 import from antd export default function...

react 自定義日曆元件

基於hooks開發的自定義日曆元件,可以根據自己需要修改 params searchbar 搜尋引數 列表資料 description 修改請備註 location grey const main props 獲取當前年份 const getfullyear date date number con...

react入門 筆記 自定義元件

方式1 工廠函式元件 簡單元件 text babel 1.定義元件 方式1 工廠函式元件 簡單元件 function mycomponent 2.渲染元件標籤 reactdom.render document.getelementbyid example1 script 方式2 es6類元件 複雜元...