反应:将CSS类添加到body标记
我想知道是否有更简单的方法将类添加到body标记 目前我正在做类似的事情 主要成分反应:将CSS类添加到body标记,css,reactjs,Css,Reactjs,我想知道是否有更简单的方法将类添加到body标记 目前我正在做类似的事情 主要成分 const MAIN_CLASSES = [ three-col, darkTheme, blueHeader, .... etc] class MainComponent extends React.Component { componentDidMount() { document.body.classList.add(...MAIN_CLASSES); } component
const MAIN_CLASSES = [ three-col, darkTheme, blueHeader, .... etc]
class MainComponent extends React.Component {
componentDidMount() {
document.body.classList.add(...MAIN_CLASSES);
}
componentWillUnmount() {
document.body.classList.remove(...MAIN_CLASSES);
}
render() ....
}
有兴趣知道别人在做什么谢谢 我能问一下为什么吗?如果您的React应用程序是在页面上唯一的元素
div中呈现的,那么为什么不将样式应用于根组件?感谢@glhrmv,我使用Khan Academy的aphrodite成功地将全局样式应用于body标签