- componentDidMount中写监听滚顶条高度方法
componentDidMount() {
this.handleHeight();
window.addEventListener('resize', this.handleHeight);
}
- 处理计算页面Table的Scroll设置高度tableHeight,tableHeight为在中初始化的属性,默认为‘’
handleHeight = () => {
if (document.body.clientHeight && document.documentElement.clientHeight) {
if (document.body.clientHeight > 800 ) {
this.setState({
tableHeight:'75vh'
});
}else if(document.body.clientHeight < 800){
this.setState({
tableHeight:'67vh'
});
}
}
}
- 记得卸载监听方法
componentWillUnmount(){
window.removeEventListener('resize', this.handleHeight);
}