更新记录
1.0.2(2025-10-30)
下载此版本
优化badge
1.0.1(2025-10-13)
下载此版本
bug修复
1.0.0(2025-09-24)
下载此版本
v1.0.0
- 初始版本发布
- 支持基础标签页
- 支持带徽章的标签页
- 支持自定义样式
- 支持自定义标签内容
- 支持非滚动模式布局
- 支持长文本徽章配置
查看更多
平台兼容性
uni-app(4.66)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
| - |
- |
- |
- |
- |
- |
√ |
√ |
- |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
| √ |
√ |
√ |
√ |
√ |
√ |
- |
√ |
√ |
√ |
√ |
liaction-tabs - UniApp 标签页组件
📱 组件简介
liaction-tabs 是一款专为 UniApp 开发的高度可定制化标签页组件,提供了丰富的样式配置和交互效果,支持滚动和非滚动两种模式,以及完善的徽章系统。适用于各类需要标签切换功能的移动端页面。
✨ 特性亮点
- 双模式布局:支持滚动模式和非滚动模式,适应不同场景需求
- 高度可定制:提供丰富的样式参数,支持自定义颜色、尺寸、间距等
- 完善的徽章系统:支持圆点、数字、文本多种徽章类型,并可自定义位置
- 灵活的指示器:支持内容宽度和标签项宽度两种指示器样式
- 平滑动画效果:标签切换时提供平滑的滚动动画
- 响应式设计:适配不同尺寸的移动设备
- 自定义插槽:支持自定义标签内容展示
🎛️ Props 参数
基础配置
| 参数名 |
类型 |
默认值 |
说明 |
| tabs |
Array |
[] |
标签数据数组,必填项 |
| activeIndex |
[Number, String] |
0 |
激活标签的索引或唯一标识,支持数字索引或字符串标识 |
| showBadge |
Boolean |
false |
是否显示徽章 |
| customClass |
String |
'' |
自定义类名 |
| customStyle |
Object |
{} |
自定义样式 |
标签样式
| 参数名 |
类型 |
默认值 |
说明 |
| tabActiveColor |
String |
'#007bff' |
激活标签的颜色 |
| tabDefaultColor |
String |
'#333' |
默认标签颜色 |
| tabMaxWidth |
String |
'120px' |
标签最大宽度 |
| tabPadding |
String |
'8px' |
标签内边距 |
| tabFontSize |
String |
'16px' |
标签字体大小 |
| tabHeight |
String |
'44px' |
标签高度 |
| tabFlex |
Boolean |
false |
是否弹性布局标签 |
| tabWrap |
Boolean |
false |
标签是否换行显示 |
| tabTextAlign |
String |
'center' |
标签文本对齐方式 |
| tabStyle |
Object |
{} |
自定义标签样式 |
指示器配置
| 参数名 |
类型 |
默认值 |
说明 |
| indicatorHeight |
String |
'3px' |
指示器高度 |
| indicatorMarginTop |
String |
'6px' |
指示器上边距 |
| indicatorShow |
Boolean |
true |
是否显示指示器 |
| indicatorWidth |
String |
'item' |
指示器宽度模式,可选 'item'、'content' |
滚动配置
| 参数名 |
类型 |
默认值 |
说明 |
| scrollEnabled |
Boolean |
true |
是否启用滚动 |
| scrollAnimation |
Boolean |
true |
是否启用滚动动画 |
非滚动模式布局
| 参数名 |
类型 |
默认值 |
说明 |
| layoutJustify |
String |
'center' |
非滚动模式下的对齐方式 |
| layoutAlign |
String |
'center' |
非滚动模式下的垂直对齐方式 |
徽章配置
| 参数名 |
类型 |
默认值 |
说明 |
| badgeDefaultType |
String |
'circle' |
默认徽章类型,可选 'circle'、'dot' |
| badgeDefaultColor |
String |
'#ff3b30' |
默认徽章颜色 |
| badgeDefaultTextColor |
String |
'#ffffff' |
默认徽章文本颜色 |
| badgeDefaultPosition |
String |
'top-right' |
默认徽章位置,可选 'top-right'、'after' |
| badgeBaseSize |
String |
'14px' |
徽章基础尺寸 |
| badgeDotRatio |
Number |
0.5 |
圆点徽章比例 |
| badgeLongTextRatio |
Number |
1.2 |
长文本徽章比例 |
| badgeFontSizeRatio |
Number |
0.8 |
徽章字体缩放比例 |
| badgeMargin |
String |
'4px' |
徽章外边距 |
| badgeMaxLength |
Number |
2 |
徽章最大字符长度 |
| badgeOverflowChar |
String |
'+' |
徽章溢出字符 |
| badgePadding |
String |
'1px' |
徽章内边距 |
📢 事件
| 事件名 |
说明 |
参数 |
| change |
标签切换时触发 |
index: 当前选中标签的索引 |
| click |
点击标签时触发 |
item: 标签数据, index: 标签索引 |
📚 使用示例
基础用法
<liaction-tabs
:tabs="tabs"
/>
<script>
export default {
data() {
return {
tabs: [
{ name: '首页' },
{ name: '发现' },
{ name: '消息' },
{ name: '我的' }
],
};
},
methods: {
}
};
</script>
带badge的标签
<liaction-tabs
:tabs="tabs"
:showBadge="true"
/>
<script>
export default {
data() {
return {
tabs: [
{ name: '首页' },
{ name: '消息', badge: 9, badgeType: 'circle' },
{ name: '通知', badge: '99+', badgeType: 'circle' },
{ name: '活动', badge: true, badgeType: 'dot' }
]
};
}
};
</script>
自定义样式
<liaction-tabs
:tabs="tabs"
tabActiveColor="#ff6700"
tabDefaultColor="#999"
indicatorHeight="4px"
indicatorMarginTop="8px"
:tabStyle="{
fontSize: '15px',
fontWeight: '500'
}"
/>
非滚动模式
<liaction-tabs
:tabs="tabs"
:scrollEnabled="false"
:tabFlex="true"
tabTextAlign="center"
/>
自定义标签内容
<liaction-tabs :tabs="tabs">
<template #tab="{ item, index }">
<view class="custom-tab-item">
<image :src="item.icon" mode="aspectFit" class="tab-icon"></image>
<text class="tab-text">{{ item.name }}</text>
</view>
</template>
</liaction-tabs>
<script>
export default {
data() {
return {
tabs: [
{ name: '首页', icon: '/static/icons/1.png' },
{ name: '分类', icon: '/static/icons/2.png' },
{ name: '购物车', icon: '/static/icons/3.png' },
{ name: '我的', icon: '/static/icons/4.png' }
]
};
}
};
</script>
<style scoped>
.custom-tab-item {
display: flex;
flex-direction: column;
align-items: center;
padding: 4px 0;
}
.tab-icon {
width: 22px;
height: 22px;
margin-bottom: 2px;
}
</style>
长文本徽章配置
<liaction-tabs
:tabs="tabs"
:showBadge="true"
:badgeLongTextRatio="1.5"
/>
<script>
export default {
data() {
return {
tabs: [
{ name: '标签一' },
{ name: '标签二', badge: '新活动', badgeType: 'circle' },
{ name: '标签三', badge: 999, badgeType: 'circle' }
]
};
}
};
</script>
📝 License
MIT
🤝 贡献指南
欢迎提交 Issues 来改进这个组件。