antd Table组件滚动条自适应

时间:2025-01-20 20:15:34
  1. componentDidMount中写监听滚顶条高度方法
componentDidMount() {
		//加载页面时计算一次
        this.handleHeight();
        //页面大小发生改变时监听计算
		window.addEventListener('resize', this.handleHeight);
}
  1. 处理计算页面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'
                });
            }
        }
    }
  1. 记得卸载监听方法
componentWillUnmount(){
        window.removeEventListener('resize', this.handleHeight);
    }