react es6 怎么設(shè)置默認(rèn)的props 于 state
1 回答

函數(shù)式編程
TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個(gè)贊
state在constructor方法里寫
...
constructor(props) {
this.state = {
n: ...
}
}
寫default props有兩種方法
//1 在組件內(nèi)部的使用static
...
static defaultProps = {
name: ...
}
//2 在組件外部
Hello.defaultProps = {
name: ...
}
- 1 回答
- 0 關(guān)注
- 1206 瀏覽
添加回答
舉報(bào)
0/150
提交
取消