element ui 的table响应式实现列隐藏

本文主要介绍的是element ui框架中的table表格中,响应式的实现列的隐藏效果。列的隐藏可以用v-if来实现,v-show没有效果,我也不知道为什么,搜也没搜到。

首先设置变量show,作为v-if的判断条件;变量screenWidth作为屏幕宽度

screenWidth:window.innerWidth,//浏览器宽度
show:true//判断条件

在mounted钩子中挂载window.onresize方法

mounted(){
	const that = this;
	
	window.onresize = ()=>{
		return (()=>{
		    window.screenWidth = window.innerWidth
                    that.screenWidth = window.screenWidth;
		})()
	}
},

在watch中实时监听浏览器窗口的宽度大小,根据需要,更改show的值,从而实现表格中列的响应式变化

watch: {
	screenWidth(val) {
		this.screenWidth = val
		console.log(this.screenWidth)
		if(this.screenWidth<1919){
			this.show = false
		}else{
			this.show = true
		}
	}
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值