设置 css 属性,使块拉伸到屏幕高度的其余部分
flex-grow: 1
现在我不知道如何在调整窗口大小时动态计算高度。到目前为止,在 componentDidMount 中组件渲染后只设置了高度
演示 https://codesandbox.io/s/dynamic-calc-height-4t1zv?file=/src/Tile.js:163-180
代码示例
class Help extends React.Component {
constructor(props) {
super(props);
this.state = {
elementHeight: 0
};
}
componentDidMount() {
this.setState({ elementHeight: this.divRef.clientHeight });
}
render() {
return (
<div className="tile" ref={(element) => (this.divRef = element)}>
Div height: {this.state.elementHeight + " px"}
</div>
);
}
}
1 个回答