vue查看更多的写法

页面布局:

<div class="my_card" v-for="(item,index) in tableData" style="margin-bottom: 10px;">
	<div v-for="column in tableColumns.slice(0,3)">
		<div class="column-box">
			<label>{{column.title}}</label>
			<div class="column_box">
				<template></template>
			</div>
		</div>
	</div>
	<div v-for="column in tableColumns.slice(3,tableColumns.length)" class="more_show" style="display: none;">
		<div class="column-box">
			<label>{{column.title}}</label>
				<div class="column_box">
				    <template></template>
				</div>
			</div>
		</div>
	<div style="text-align: center;">
		<el-button type="primary" class="button" v-on:click="seeMore(index)" style="font-size: 14px;margin-top: 10px;">查看更多</el-button>
	</div>
</div>

js:

//查看更多
seeMore:function(index){
	var my_card = document.getElementsByClassName("my_card")
	var more_show = my_card[index].childNodes
	console.log(my_card)
	//先清除其他的查看更多样式
	for(var i=0;i<my_card.length;i++){
		var more_show_other = my_card[i].childNodes
		for(var j=0;j<more_show_other.length;j++){
			if(more_show_other[j].nodeType==1&&more_show_other[j].className=="more_show"){
				more_show_other[j].style.display = "none"
			}
		}
	}
	//再打开当前的查看更多
	for(var i=0;i<more_show.length;i++){
		if(more_show[i].nodeType==1&&more_show[i].className=="more_show"){
			 more_show[i].style.display = "block"
		}
	}
},

样式:

/*卡片视图添加样式*/
.my_card{
	width: 98%;
	font-size:16px;
	border: 1px solid #EBEEF5;
	box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
	transition: .3s;
	background-color: #fff;
	color: #303133;
	border-radius: 4px;
	overflow: hidden;
	padding: 20px;
	box-sizing: border-box;
}
.my_card label{
	display: block;
	width: 40%;
	height: 45px;
	line-height: 45px;
	float: left;
}
.my_card>div:first-child{
	font-weight: 600;
	border-bottom: 1px solid #eee;
}
.my_card>div:last-child{
	font-weight: 600;
	border-top: 1px solid #eee;
}

最终效果:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值