选项卡案例【vue】
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#content{
width: 200px;
height: 200px;
background: #ccc;
overflow: hidden;
}
#content>div{
width: 200px;
height: 200px;
}
.active{
background: red
}
</style>
</head>
<body>
<div id="app">
<button
v-for="(item,index) in btns"
:class="index == activeIndex?'active':''"
@click="handleToggle(index)"
>{{item}}</button>
<div id="content">
<div v-for="(item,index) in contents" v-show="activeIndex == index">{{item.text}}</div>
</div>
</div>
</body>
</html>
<script src="vue.js"></script>
<script>
var vm = new Vue({
el:"#app",
data:{
activeIndex:0,
btns:['按钮一','按钮二','按钮三'],
contents:[
{
text:"页面一"
},
{
text:"页面二"
},
{
text:"页面三"
}
]
},
methods: {
handleToggle(index){
this.activeIndex = index;
}
},
})
</script>