目录
一、比较常见的普通tab选项卡
代码块部分
<template>
<view class="content">
<view class="hand">
<view class="dataInfo">
<view class="dataList" @click="navIndex = index" v-for="(item,index) in dataInfo" :key='item.titleId'>
<text :class="navIndex==index?'activite':''">{{item.title}}</text>
</view>
</view>
</view>
<!-- 内容切换开始 -->
<view class="main">
<view class="htmlContent" v-if="navIndex==0">
<text>html</text>
</view>
<view class="jsContent" v-if="navIndex==1">
<text>javascript</text>
</view>
<view class="cssContent" v-if="navIndex==2">
<text>css</text>
</view>
<view class="vueContent" v-if="navIndex==3">
<text>vue</text>
</view>
</view>
<!-- 内容切换结束 -->
</view>
</template>
<script>
export default {
data() {
return {
navIndex: 0,
dataInfo: [{
title: 'HTML',
titleId: 1
},
{
title: 'JavaScript',
titleId: 2
},
{
title: 'CSS',
titleId: 3
},
{
title: 'VUE',
titleId: 4
}
]
}
}
}
</script>
<style>
.content {
padding: 20rpx;
}
.hand .dataInfo {
display: flex;
justify-content: space-between;
text-align: center;
}
.hand .dataInfo .dataList {
flex: 1;
border-right: 1px solid #bcbcbc;
border-top: 1px solid #bcbcbc;
}
.hand .dataInfo .dataList:first-child {
border-left: 1px solid #bcbcbc;
}
.hand .dataInfo .dataList text {
font-size: 30rpx;
color: grey;
background-color: #e6e6e6;
display: block;
line-height: 70rpx;
}
.hand .dataInfo .dataList text.activite {
background-color: grey;
color: #fff;
}
.main {
border: 1px solid #bcbcbc;
height: 200px;
}
.main .htmlContent,
.cssContent,
.jsContent,
.vueContent text {
font-size: 40rpx;
color: #0F254E;
display: block;
padding: 20rpx;
}
</style>
二、使用scroll-view滑动
代码块部分
<template>
<view class="content">
<view class="hand">
<scroll-view scroll-x="true" style="white-space: nowrap;">
<view class="dataInfo">
<view class="dataList" v-for="(item,index) in dataInfo" :key='item.titleId' :id="item.titleId"
@click="navIndex = index">
<text :class="navIndex==index?'activite':''">{{item.title}}</text>
</view>
</view>
</scroll-view>
</view>
<!-- 内容切换开始 -->
<view class="main">
<view class="htmlContent" v-if="navIndex==0">
<text>html</text>
</view>
<view class="jsContent" v-if="navIndex==1">
<text>javascript</text>
</view>
<view class="cssContent" v-if="navIndex==2">
<text>css</text>
</view>
<view class="vueContent" v-if="navIndex==3">
<text>vue</text>
</view>
<view class="reactContent" v-if="navIndex==4">
<text>react</text>
</view>
</view>
<!-- 内容切换结束 -->
</view>
</template>
<script>
export default {
data() {
return {
navIndex: 0,
dataInfo: [{
title: 'HTML',
titleId: 'html'
},
{
title: 'JavaScript',
titleId: 'js'
},
{
title: 'CSS',
titleId: 'css'
},
{
title: 'VUE',
titleId: 'vue'
},
{
title: 'React ',
titleId: 'react '
}
]
}
}
}
</script>
<style>
.content {
padding: 20rpx;
}
.hand .dataInfo {
display: flex;
text-align: center;
width: 100%;
}
.hand .dataInfo .dataList {
border-right: 1px solid #bcbcbc;
border-top: 1px solid #bcbcbc;
}
.hand .dataInfo .dataList:first-child {
border-left: 1px solid #bcbcbc;
}
.hand .dataInfo .dataList text {
font-size: 30rpx;
color: grey;
background-color: #e6e6e6;
display: block;
line-height: 70rpx;
width: 200rpx;
}
.hand .dataInfo .dataList text.activite {
background-color: grey;
color: #fff;
}
.main {
border: 1px solid #bcbcbc;
height: 200px;
}
.main .htmlContent,
.cssContent,
.jsContent,
.reactContent,
.vueContent text {
font-size: 40rpx;
color: #0F254E;
display: block;
padding: 20rpx;
}
</style>
三、scroll-view滑动 + swiper轮播联动
代码块部分
<template>
<view class="content">
<view class="hand">
<scroll-view scroll-x="true" style="white-space: nowrap;">
<view class="dataInfo">
<view class="dataList" v-for="(item,index) in dataInfo" :key='item.titleId' :id="item.titleId"
@click="navIndex = index">
<text :class="navIndex==index?'activite':''">{{item.title}}</text>
</view>
</view>
</scroll-view>
</view>
<!-- 内容切换开始 -->
<view class="main">
<swiper :current="navIndex" @change="tabChange">
<swiper-item>
<view class="htmlContent" v-if="navIndex==0">
<text>html</text>
</view>
</swiper-item>
<swiper-item>
<view class="jsContent" v-if="navIndex==1">
<text>javascript</text>
</view>
</swiper-item>
<swiper-item>
<view class="cssContent" v-if="navIndex==2">
<text>css</text>
</view>
</swiper-item>
<swiper-item>
<view class="vueContent" v-if="navIndex==3">
<text>vue</text>
</view>
</swiper-item>
<swiper-item>
<view class="reactContent" v-if="navIndex==4">
<text>react</text>
</view>
</swiper-item>
</swiper>
</view>
<!-- 内容切换结束 -->
</view>
</template>
<script>
export default {
data() {
return {
navIndex: 0,
dataInfo: [{
title: 'HTML',
titleId: 'html'
},
{
title: 'JavaScript',
titleId: 'js'
},
{
title: 'CSS',
titleId: 'css'
},
{
title: 'VUE',
titleId: 'vue'
},
{
title: 'React ',
titleId: 'react '
}
]
}
},
methods: {
tabChange(e) {
this.navIndex = e.detail.current
},
}
}
</script>
<style>
.content {
padding: 20rpx;
}
.hand .dataInfo {
display: flex;
text-align: center;
width: 100%;
}
.hand .dataInfo .dataList {
border-right: 1px solid #bcbcbc;
border-top: 1px solid #bcbcbc;
}
.hand .dataInfo .dataList:first-child {
border-left: 1px solid #bcbcbc;
}
.hand .dataInfo .dataList text {
font-size: 30rpx;
color: grey;
background-color: #e6e6e6;
display: block;
line-height: 70rpx;
width: 200rpx;
}
.hand .dataInfo .dataList text.activite {
background-color: grey;
color: #fff;
}
.main {
border: 1px solid #bcbcbc;
height: 200px;
}
.main .htmlContent,
.cssContent,
.jsContent,
.reactContent,
.vueContent text {
font-size: 40rpx;
color: #0F254E;
display: block;
padding: 20rpx;
}
</style>