1、通过静态属性设置props默认值
class LayOut extends Component {
// 通过静态属性设置props默认值
static defaultProps = {
isShowBack: true
}
render() {
const { title, children, isSHowFooter, isShowBack } = this.props
return (
<div className="layout">
<header>
<Header title = { title } isShowBack = { isShowBack }/>
</header>
<main>
{ children }
</main>
{
isSHowFooter? <footer>
第三方登陆
</footer>: ""
}
</div>
)
}
}
export default LayOut
2、通过设置props默认属性
// 设置props默认属性
LayOut.defaultProps = {
isShowBack: true
}
class LayOut extends Component {
render() {
const { title, children, isSHowFooter, isShowBack } = this.props
return (
<div className="layout">
<header>
<Header title = { title } isShowBack = { isShowBack }/>
</header>
<main>
{ children }
</main>
{
isSHowFooter? <footer>
第三方登陆
</footer>: ""
}
</div>
)
}
}
export default LayOut