表格高度自适应

方法一:

<Table :height="tableHeight" border :columns="addBao" :data="addBaoTable"></Table>
import {getClassNameHeight} from '@/utils/index.js';//引入获取高度方法

data(){
	return{
		tableHeight: 300, //表单高度385
	}
}

methods:{
		getTableHeight() { //获取表格高度
				let _this = this;
				this.$nextTick(() => {
					try {
						let sectionRightH = getClassNameHeight('section-right');
						let ivuBreadcrumbH = getClassNameHeight('tableHeader');
						let ivutabsH = getClassNameHeight('ivu-tabs-bar');
						let tabsH = getClassNameHeight('ivu-tabs-nav-scroll ');
						let ivuPageH = getClassNameHeight('ivu-page');
						_this.tableHeight = sectionRightH - (ivuBreadcrumbH + ivutabsH + tabsH + ivuPageH + 30);
					} catch (err) {
						console.log(err)
					}
				})
			},
},
mounted() {
			this.getTableHeight();
		}

方法二:

data(){
	return{
			balanceH: 0,
	}
},

methods:{
	Height() {
				this.$store.dispatch("figure");//vuex获取高度
			},
},
computed: {//计算高度
			height() {
				return this.$store.state.user.height - this.balanceH;
			}
},

mounted(){
		this.Height();
		let balance = document.getElementsByClassName("top")[0].clientHeight; //不同屏幕高度计算差额
		this.balanceH = balance;
},

vuex

state:{
	height:'',
},

mutations:{
figure:state =>{ 
            state.height=parseInt(document.body.clientHeight)-165;
        },
}

第三种:最易理解

html

<Table border :columns="columns" :data="columnsdata" :height="tableHeight" class="tbs"></Table>

js

data(){
	return{
			tableHeight = 300,
	}
},
methods:{
	getTableHeight() { //获取表格高度
				let _this = this;
				this.$nextTick(() => {
					try {
						let sectionRightH = document.getElementsByClassName('sider-container')[0].clientHeight;
						let ivuBreadcrumbH = document.getElementsByClassName('searchContent')[0].clientHeight;
						let ivuPageH = document.getElementsByClassName('page')[0].clientHeight;
						_this.tableHeight = sectionRightH - (ivuBreadcrumbH + ivuPageH);//
					} catch (err) {
						console.log(err);
					}
				})
			},
},
mounted() {
			this.getTableHeight();
			this.loadData();
		}

第三种方法
在表格属性添加 ref=“table”, :height=“tableHeight”

<Table border :columns="columns1" :data="data1" ref="table"   :height="tableHeight" ></Table>

在data里面添加表格初始高度

data(){
    return  {
           tableHeight:100,
      }
}
 mounted() {
      /*    
        表格高度自适应
          window.innerHeight是浏览器的可用高度  ,
          this.$refs.table.$el.offsetTop是表格距离浏览器可用高度顶部的距离
          减去60,因为分页要的高度
        */
          this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 60
      }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现antd表格高度自适应,有几种方法可以尝试。首先,通过修改组件中的width属性为minWidth属性来解决表格自适应宽度的问题。具体做法是在columns数组中的每个对象中将width属性改为minWidth属性,例如:{ title: '账户名', key: 'accountName', fixed: 'left', minWidth: 150 }。这样就可以确保表格的宽度不会溢出容器。 其次,如果想要让分页部分的底边自适应屏幕高度,可以使用CSS选择器::v-deep和calc()函数来设置表格高度。例如,使用以下CSS代码可以实现分页部分底边自适应屏幕高度的效果:.ant-table { height: calc(100vh - 170px); }。这样就可以确保表格高度在不同屏幕大小下自适应。 另外,如果需要实现表格内容区域可以滚动的效果,可以使用以下CSS代码来设置表格高度和滚动属性:.ant-table-scroll { height: calc(100vh - 170px); overflow: auto scroll; }。这样就可以在表格内容超出容器高度时显示滚动条。 此外,还可以通过监听窗口大小变化来动态修改表格高度。可以在mounted钩子函数中添加window.onresize事件监听窗口大小的变化,并使用document.body.clientHeight来获取窗口的高度。然后根据这个值来修改表格高度。具体做法可以参考以下代码: ```typescript // 在组件内部 public clientHeight = 0; // 监听视窗大小变化 mounted() { const that = this; window.onresize = () => { return (() => { that.clientHeight = document.body.clientHeight; // 可在这里进行修改操作 // ... })(); }; } // Watch监听clientHeight属性,并在回调函数内部进行修改操作 @Watch('clientHeight') private getHeight() { // 修改操作 // ... } ``` 通过上述方法,可以实现antd表格高度自适应。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值