ReactJS筆記之props 四

2021-08-20 16:11:58 字數 539 閱讀 9498

專案應用中經常需要在使用乙個元件的時候傳遞引數,這個時候可以把引數放在標籤的屬性當中,所有的屬性都會作為 props 物件的鍵值。

例如:

class

index

extends

component } />

)}}`

這個時候 intext 和 outtext 兩個引數封裝到乙個叫 str 的物件引數內,然後傳到maxbutton元件中。

maxbutton的內部就要用 this.props.str 來獲取到到引數了:

class

maxbutton

extends

component

} handleclickonlikebutton () )

} render ()

return (

)}}

元件內部可以通過 this.props 獲取到配置引數,元件可以根據 props 的不同來確定自己的顯示形態,達到可配置的效果。

ReactJS入門之元件

元件是react中最重要也是最核心的概念,乙個網頁,可以被拆分成乙個個的元件 在react中,這樣定義乙個元件 import react from react class helloworld extends react.component 內容 export default helloworld ...

ReactJS入門之元件

元件是react中最重要也是最核心的概念,乙個網頁,可以被拆分成乙個個的元件 在react中,這樣定義乙個元件 import react from react 第一步,匯入react class helloworld extends react.component 內容 jsx語法 export d...

ReactJS入門之JSX語法

jsx語法就是,可以在js檔案中插入html片段,是react自創的一種語法。jsx語法會被babel等轉碼工具進行轉碼,得到正常的js 再執行。使用jsx語法,需要2點注意 1.所有的html標籤必須是閉合的,如 hello world,寫成這樣是不可以的 2.在jsx語法中,只能有乙個根標籤,不...