vue实现tab选项卡效果

刚接触vue,还没完全适应vue的响应式解构,刚遇到这个需求下意识还是dom操作,下面上vue实现的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<script src="https://cdn.bootcss.com/vue/2.5.13/vue.js"></script>
<style type="text/css">
body,html{
margin: 0;
padding: 0;
}
.father{
width: 100%;
display: flex;
}
.father span{
flex:1;
text-align: center;
background-color: #31c27c;
color:#fff;
height: 40px;
line-height: 40px;
}
.active{
color:red!important;
background-color: blue!important;
}
</style>
</head>
<body>
<div id="app">
<div class="father">
<span :class="isshow==0?'active':''" @click='changetag(0)'>我是tab1</span>
<span :class="isshow==1?'active':''" @click='changetag(1)'>我是tab2</span>
</div>
<div class="son">
<div v-show='isshow==0'>我是tab1里面的内容</div>
<div v-show='isshow==1'>我是tab2里面的内容啊啊啊啊啊</div>
</div>
</div>
</body>
<script type="text/javascript">
var app=new Vue({
el:'#app',
data:{
isshow:0
},
methods:{
changetag:function(idx){
this.isshow=idx;
}
}
})
</script>
</html>

demo看这里


vue实现tab选项卡效果
https://xypecho.github.io/2018/02/17/vue实现tab选项卡效果/
作者
很青的青蛙
发布于
2018年2月17日
许可协议