我有一个React组件,其中componentDidMount()' I want to set the
最小高度为property of an element where
className =“content-wrapper”为“600px”。React设置具有特定className的元素的min-height属性
我曾尝试以下:
componentDidMount() {
document.getElementsByClassName('content-wrapper').style.minHeight = "600px"
}
不幸的结果在下面的错误:
Uncaught TypeError: Cannot set property 'minHeight' of undefined
at MyComponent.componentDidMount
我仍然得到阵营的窍门,并希望得到任何帮助可能实现这一目标。谢谢!
content-wrapper是你在一个反应组件中创建的元素还是仅仅使用标准的html或js? –
这只是一个'div'标签 –
好吧,如果你在反应组件中创建了这个'div'标签,那么它将是一个虚拟的'div'。在这种情况下,接受的答案不是你想要的,因为你直接修改了不好的DOM。如果它是一个正常的html文件中的div或使用普通的JS创建的,那么它就没有问题。 –