用Vue实现好友分组效果

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>tab标签</title>
<style>
body {
	background-color: #999;
}
#box {
	max-width: 360px;
	min-height: 640px;
	background-image: linear-gradient(to right bottom, #432b8b, #89049e);
	background-size: cover;
	margin: 10px auto;
	padding: 20px;
	box-sizing: border-box;
}
.panel {
	margin-bottom: 10px;
	background-color: rgba(0,0,0,.3);
	border-radius: 5px;
	overflow: hidden;
}
.panel-header {
	position: relative;
	padding: 10px 15px 10px 32px;
	cursor: pointer;
	color: rgba(255,255,255,.6);
}
.panel-header:before {
	position: absolute;
	left: 15px;
	top: 14px;
	content: "";
	width: 0;
	height: 0;
	border-width: 7px 0 7px 8px;
	border-style: solid;
	border-color: transparent;
	border-left-color: rgba(255,255,255,.3);
	transition: all .3s;
}
.active .panel-header {
	background-color: rgba(228,0,127,.8);
	transform: rotateZ(0);
	color: rgb(255,255,255);
}
.active .panel-header:before {
	transform-style: preserve-3d;
	transform: rotateZ(90deg);
	transition: all .3s;
	border-left-color: rgba(255,255,255,.6);
}
.panel-body {
	padding: 10px 20px;
}
.list {
	margin: 0;
	padding: 0;
	list-style: none;
}
.list li {
	line-height: 2em;
}
.list li a {
	color: rgba(255,255,255,.4);
	text-decoration: none;
}
.list li a:hover {
	color: #fff;
}
</style>
</head>
<body>
<main id="box">
  <div class="panel" v-for="panel,index in panels" :class="{active:index===currentIndex}">
    <div class="panel-header" @click="panelSwitch(index)">{{panel.title}}</div>
    <div class="panel-body" v-show="index===currentIndex">
      <ul class="list">
        <li v-for="item in panel.list"><a href="#">{{item}}</a></li>
      </ul>
    </div>
  </div>
</main>
<script src="https://cdn.jsdelivr.net/npm/vue"></script> 
<script>
var vm=new Vue({
	el:'#box',
	data:{
		panels: [			
			{
				title: '中国',
				list: ['北京市','上海市','广州市','深圳市']
			},
			{
				title: '美国',
				list: ['纽约市','洛杉矶市','芝加哥市','拉斯维加斯市']
			},
			{
				title: '英国',
				list: ['伦敦市','伯明翰市','利兹市','格拉斯哥市']
			}
		],
		currentIndex: '' //存储当前索引值
	},
	methods:{
		panelSwitch(index){
			this.currentIndex = this.currentIndex === index ? '' : index; //当前索引值等于当前索引值,清空索引值;否则设置为当前索引值
		}
	}
});	
</script>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值