这是我MainLayout组件:哪些React组件应该与参数一起使用?
export const MainLayout = ({header, content, footer}) =>(
<div>
<header>
{header}
</header>
<main>
<Paper style={contentStyle} zDepth={1}>
{content}
</Paper>
</main>
<footer>
<Paper style={contentStyle}>
{footer}
</Paper>
</footer>
</div>);
这是我与React.Component
export class MainLayout extends React.Component{
constructor({header, content, footer}){
super();
this.header = header;
this.content = content;
this.footer = footer;
}
render(){
return(
<div>
<header>
{this.header}
</header>
<main>
<Paper style={contentStyle} zDepth={1}>
{this.content}
</Paper>
</main>
<footer>
<Paper style={contentStyle}>
{this.footer}
</Paper>
</footer>
</div>
)
}}
当我使用我的第一个MainLayout组件的所有标题,内容MainLayout和页脚正常工作。我想添加构造函数()和componentDidMount()但我不能!所以,我试图使用ES6类(我的第二个MainLayout的React.Component)与construcor()我添加3个参数。这对我有用! 但是,当我链接到其他页面时,内容不响应。我的意思是旧的内容仍然是一样的。 Unitl我刷新页面,然后内容被更改!
那么你能告诉我,如果我在创建这些组件时犯了错误吗? 非常感谢你们的援助:d
我将纸张样式添加到内容:D 非常感谢!这真的帮助我! –
欢迎。 “contentStyle”不应该成为道具之一吗? –
是的!现在我遇到了问题。当屏幕响应时(大,中,小),我希望contentStyle自动更改。或者你想让我把contentStyle放入构造函数中?我很抱歉,如果我不明白你的观点:D –