React系列--三大屬性 props refs state
阿新 • • 發佈:2018-11-21
一個 this 傳值 實的 值傳遞 取值 gin 對象 組件
https://blog.csdn.net/ImagineCode/article/details/82429819
props:組件外部向組件內部傳值用,標簽屬性都掛載在 props上,
<AddTodo add={this.add} length={todos.length}/>
AddTodo 組件內部就可以使用 props來獲取值, this.props.length
組件內部也可以獲取外部傳遞的方法, this.props.add(xxx) //獲取add方法並傳值,這樣同時也可以把內部的值傳遞給外部組件的add方法處理。
refs:標識組件內部標簽對象,組件內以操作真實的目標dom
<input ref="newTodo"> this.refs.newTodo.value //獲取input中輸入的值 註意此處一個是 ref 一個是 refs
state:待研究
this.state({
attr1:state1,
attr2:state2
});
React系列--三大屬性 props refs state