我是靠谱客的博主 坚强砖头,这篇文章主要介绍vue里的tab栏切换,配合指令v-for,v-if,v-bind使用,现在分享给大家,希望可以做个参考。

第一种

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<template> <view v-for="(item,index) in list" :key="index"> <view @click=cur=index :class="{active: cur==index}">{{ item }}</view> </view> <view> <view v-for="(itm,index) in tabMain" :key="index" v-if="cur==index">{{ itm }}</view> </view> </template> <script> export default { data() { return { list: ["标题一","标题二"], tabMain: ["内容一", "内容二"] } } } </script> <style> .active { color: blue } </style>

第二种

复制代码
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
<template> <view> <ul> <li @click="cur=0" :class="{active:cur == 0}">标题一</li> <li @click="cur=1" :class="{active:cur == 1}">标题一</li> </ul> <view> <view v-if="cur==0">内容一</view> <view v-if="cur==1">内容二</view> </view> </view> </template> <script> export default { data() { return { cur: 0 //默认显示第一个 } } } </script> <style> .active { color: blue; } </style>

第三种

复制代码
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
<template> <view v-for="(item,index) in list" :key="index"> <view @click="toIsShow(index)"> <text v-if="item.isShow">{{ item.txt }}</text> <text v-if="!item.isShow">{{ item.distxt }}</text> </view> </view> </template> <script> export default { data() { return { list: [ { id: 0, txt: '已关注', distxt: '关注', isShow: true }, { id: 1, txt: '已关注', distxt: '关注', isShow: true } ] } }, methods: { toIsShow(index) { this.list[index].isShow = !this.list[index].isShow; } } } </script>

最后

以上就是坚强砖头最近收集整理的关于vue里的tab栏切换,配合指令v-for,v-if,v-bind使用的全部内容,更多相关vue里内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部