element table max-height问题

3 篇文章 0 订阅

第一步:utils目录下创建一个文件为directive,新建auto-height.js文件,

export default {

componentUpdated(el, binding, vnode) {

const ctx = vnode.context;

if (!ctx || typeof ctx[binding.arg] === 'undefined' || ctx.autoHeightResizeListenner) return;

 

ctx.autoHeightResizeListenner = () => {

let top = el.offsetTop;

let cur = el.offsetParent;

while(cur !== null) {

top += cur.offsetTop;

cur = cur.offsetParent;

}

const h = (window.innerHeight - top) + binding.value;

ctx[binding.arg] = Math.max(h, 100 );

};

window.addEventListener('resize', ctx.autoHeightResizeListener, false);

setTimeout(ctx.autoHeightResizeListenner, 50);

},

unbind(el, binding, vnode){

const ctx = vnode.context;

if(ctx && ctx.autoHeightResizeListener) {

window.removeEventListener('resize', ctx.autoHeightResizeListener, false);

ctx.autoHeightResizeListener = null;

}

},

};

全局配置 在main.js中导入 auto-height.js文件

import autoHeight from './utils/directive/auto-height';

Vue.directive('auto-height',autoHeight)

第三步:组件中需要的标签添加两个属性 v-auto-height:maxHeight = ‘-10’ :max-height=“maxHeight”

maxHeight 可以随便在data定义一个值

<el-table   v-auto-height:maxHeight = '-10' :max-height="maxHeight"></el-table>


export default {
    data() {
        return {
			maxHeight:'500'  //maxHeight  可以随便在data定义一个值
		}
        }

转载自用
出处 https://blog.csdn.net/m13302979400/article/details/88538041

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值