index.vue
3.6 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!--
NutUI Tabs 自定义标签栏测试页面
@description 测试 NutUI Tabs 组件的自定义标签栏功能
@page pages/test-tabs
@created 2026-01-31
-->
<template>
<view class="test-tabs-page">
<view class="tabs-container">
<nut-tabs v-model="activeTab">
<!-- 自定义标签栏 - 参考 FilterTabs 样式 -->
<template #titles>
<view class="filter-tabs-wrapper">
<view
v-for="item in tabList"
:key="item.paneKey"
:class="[
'filter-tab-item',
activeTab === item.paneKey ? 'filter-tab-active' : 'filter-tab-inactive'
]"
@tap="handleTabClick(item.paneKey)"
>
<text class="filter-tab-text">{{ item.title }}</text>
</view>
</view>
</template>
<!-- Tab 内容 -->
<nut-tab-pane v-for="item in tabList" :key="item.paneKey" :pane-key="item.paneKey">
<view class="tab-content">
<text class="content-text">{{ item.content }}</text>
<view class="content-list">
<view v-for="i in 3" :key="i" class="list-item">
<text>{{ item.title }} - 列表项 {{ i }}</text>
</view>
</view>
</view>
</nut-tab-pane>
</nut-tabs>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
// 当前激活的 Tab
const activeTab = ref('c1')
// Tab 列表数据
const tabList = ref([
{
title: 'Tab 1',
paneKey: 'c1',
content: '这是 Tab 1 的内容区域'
},
{
title: 'Tab 2',
paneKey: 'c2',
content: '这是 Tab 2 的内容区域'
},
{
title: 'Tab 3',
paneKey: 'c3',
content: '这是 Tab 3 的内容区域'
},
{
title: 'Tab 4',
paneKey: 'c4',
content: '这是 Tab 4 的内容区域'
},
{
title: 'Tab 5',
paneKey: 'c5',
content: '这是 Tab 5 的内容区域'
},
{
title: 'Tab 6',
paneKey: 'c6',
content: '这是 Tab 6 的内容区域'
}
])
/**
* 处理 Tab 点击事件
* @param {string} paneKey - Tab 的 paneKey
*/
const handleTabClick = (paneKey) => {
activeTab.value = paneKey
}
</script>
<style lang="less">
.test-tabs-page {
min-height: 100vh;
background-color: #f5f5f5;
}
.page-header {
padding: 40px 30px;
background-color: #fff;
border-bottom: 1px solid #eee;
}
.page-title {
font-size: 32px;
font-weight: bold;
color: #333;
}
.tabs-container {
background-color: #fff;
margin-top: 20px;
}
// FilterTabs 风格的标签栏
.filter-tabs-wrapper {
display: flex;
overflow-x: auto;
padding: 24px 30px;
gap: 24rpx;
transition: all 0.3s ease;
// 隐藏滚动条
&::-webkit-scrollbar {
display: none;
width: 0;
height: 0;
}
-ms-overflow-style: none;
scrollbar-width: none;
}
.filter-tab-item {
display: flex;
align-items: center;
justify-content: center;
padding: 16rpx 32rpx;
border-radius: 9999rpx;
white-space: nowrap;
transition: all 0.3s ease;
flex-shrink: 0;
}
.filter-tab-active {
background-color: #2563EB; // 蓝色背景
color: #fff;
}
.filter-tab-inactive {
background-color: #F3F4F6; // 灰色背景
color: #6B7280;
}
.filter-tab-text {
font-size: 28rpx;
font-weight: 500;
}
// Tab 内容区域
.tab-content {
padding: 30px;
min-height: 400px;
}
.content-text {
font-size: 28px;
color: #333;
margin-bottom: 30px;
display: block;
}
.content-list {
margin-top: 30px;
}
.list-item {
padding: 24px;
background-color: #f9f9f9;
border-radius: 12px;
margin-bottom: 20px;
font-size: 26px;
color: #666;
}
</style>