<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../lib/vue.js"></script>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
ul{
list-style: none;
display: flex;
}
li{
flex: 1;
height:50px ;
line-height: 50px;
text-align: center;
}
.active{
background-color: red;
}
</style>
</head>
<body>
<!-- vue实现点击变色 -->
<div id="box">
<ul>
<li v-for="(data,index) in list" @click="handle(index)" :class="cu===index?'active':''">
{{data}}
</li>
</ul>
</div>
<script type="text/javascript">
new Vue({
el:"#box",
data:{
list:[111,222,333],
active:'',
cu:''
},
methods:{
handle(index){
this.cu=index;
}
}
})
</script>
</body>
</html>
vue小demo- 简单实现选项卡
最新推荐文章于 2024-02-29 12:39:55 发布