子組件為ChildModal, 其實(shí)就是對(duì)antd modal的封裝:class ChildModal = ()=>{ // 其他邏輯...
return(
<Modal
visible={this.props.visible}
width={500}
> // ...
</Modal>
)
}那么父組件如何引用?方案一:
render(){
return( <div>
<ChildModal visible={visible} />
</div>
)
}
方案二:
render(){
return( <div>
{
visible && <ChildModal visible={true} />
} </div>
)
}
1 回答
叮當(dāng)貓咪
TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊
兩種都可以。
我習(xí)慣使用第二種,因?yàn)檫@樣可以在不顯示的時(shí)候,徹底u(yù)nmount掉。
添加回答
舉報(bào)
0/150
提交
取消
