<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tab切换</title>
<script src="js/vue.js"></script>
<style>
*{
margin:0;
padding: 0;
list-style: none;
}
#app{
position: absolute;
left: 50%;
top: 50%;
margin: -175px 0 0 -200px;
width: 400px;
height: 350px;
border:1px solid #ccc;
}
.nav{
width:100%;
height: 50px;
}
li{
float: left;
width: 100px;
height: 50px;
line-height:50px;
text-align: center;
background-color: #EDEDED;
}
.active{
background: deepskyblue;
color: #fff;
}
p{
font-size: 22px;
font-weight: 600;
text-align: center;
line-height: 40px;
}
</style>
</head>
<body>
<div id="app">
<ul class="nav">
<li v-for="(item,index) of list"
:class="{active: ind == index}"
@click="clickTab(index)">{{item}}
</li>
</ul>
<p>{{list[ind]}}</p>
</div>
<script>
new Vue({
el:'#app',
data:{
list:['HTML','CSS','javaScript','vue'],
ind:0
},
methods:{
clickTab(index){
this.ind = index;
}
}
})
</script>
</body>
</html>
vue一个简单的tab切换
最新推荐文章于 2023-05-11 17:56:14 发布