I am having issues with react Plotly displaying correctly when a graph loaded in a hidden tab is selected. 似乎这是一个已知问题,除了默认选项卡之外的每个选项卡都不会适当地调整大小,因为它不知道隐藏图的尺寸。
为了解决这个问题,我想动态更新选项卡高度以等于默认选项卡的高度。像这样:选择选项卡时更改 div 高度。
问题是,我无法在 DOM 加载时选择选项卡高度值。我想我可以添加一个带有 evenlistener 的 componentDidMount 函数来进行窗口加载,如下所示:
constructor(props) {
super(props)
this.state = {
value: 0
};
this.handleLoad = this.handleLoad.bind(this);
}
componentDidMount() {
window.addEventListener('load', this.handleLoad);
}
handleLoad() {
console.log("firstTab height: " + $('#firstTab').offsetHeight)
}
这个问题是,控制台日志正在输出 firstTab height: undefined。
当我检查网页并将命令 $('#firstTab').offsetHeight 放入控制台时,我能够得出 697 像素的高度。
我不想硬编码标签像素大小。谁能指导我为什么我无法在窗口加载时获取元素高度?