我正在学习 Reactjs,我正在渲染一个包含一些组件的简单页面。 其中一个组件是:
class Header extends React.Component {
render(){
return (
<header>
<div class="container">
<Logo />
<Navigation />
</div>
</header>
);
}
}
export default Header
我正在使用 Bootstrap CSS 我希望 header 中的 div
使用 container
的样式,但是在构建之后,下课了。
有没有办法强制组件中的属性类?
最佳答案
您必须使用 className
属性而不是 class
属性,例如:
class Header extends React.Component {
render() {
return (
<header>
<div className="container">
<Logo />
<Navigation />
</div>
</header>
);
}
}
查看列表Supported Attributes 在文档中。
All attributes are camel-cased and the attributes
class
andfor
areclassName
andhtmlFor
, respectively, to match the DOM API specification.
关于javascript - 为什么要删除我的类(class)名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35103683/