本節(jié)知識點
(1) 獲取到元素的節(jié)點。
(2) React的生命周期
(1) 在react中要想獲取到元素節(jié)點有兩種方式
(i)第一種e.target
例如
<button onClick="this.change.bind(this)">點擊我</button>
//然后在方法里面可以直接e.target獲取到元素
(ii)第二種通過ref
<input
value={this.state.value2}
onChange={this.change.bind(this)}
ref={input1 => {
//input1表示整個dom
//this.inputid 表示別名
this.inputid = input1
}}
/>
然后在使用的時候就是
e.target.value 等價于 this.inputid.value
可以直接使用了
(2) React 的生命周期
先說一下REACT的步驟
(1) componentWillMount(){}
(2) componentDidMount(){}
這里要說明(3)返回的是個布爾值增拥。要是false的話同級之間數(shù)據(jù)變化他不會更新DOM的破婆,要是true的話他會更新的涮总。但是要是父級傳遞過來的數(shù)據(jù)變化了,那他渲染的時候還是會渲染的
(3) shouldComponentUpdate(){}
(4) componentWillUpdate(){}
(5) componentDidUpdate(){}
(6)父元素給子元素傳值的時候祷舀,值改變時候會觸發(fā)瀑梗,第一次不觸發(fā)
(6) componentWillReceiveProps(){}
(7) 組件被移除的時候
(7) componentWillUnmount(){}
PS:性能優(yōu)化
shouldComponentUpdate(nextProps,nextState){
if(nextProps.content!==this.props.content){
return true;
}else{
return false
}
}
一般情況下獲取數(shù)據(jù)的話,都寫在
componentDidMount(){}