01
可滚动
<cu-tabs :list="longList" :current="cur" @change="onCur" @longPress="onLongPress" />
标签页用于在同级内容间切换,适合频道、分类等少量页签的场景。
整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。
# 1 整目录放进工程(easycom 自动解析) your-project/ └── uni_modules/ └── colorui-x/ # 2 App.uvue 全局引入主题层(一次) @import 'uni_modules/colorui-x/theme/base.css'; @import 'uni_modules/colorui-x/theme/layout.css'; @import 'uni_modules/colorui-x/theme/color.scss'; // 颜色工具类(.bg-* / .text-*) # 3 页面里直接用,不写 import(只编译用到的组件) <cu-tabs /> # 4 单个组件也可以显式引入(可选,不用 easycom 时) import CuTabs from '@/uni_modules/colorui-x/components/cu-tabs/cu-tabs.uvue'
组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。
| Android | iOS | HarmonyOS | Web(H5) | 微信小程序 | 支付宝小程序 |
|---|---|---|---|---|---|
| √ | — | — | √ | — | — |
Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。
Web 列只表示已编出可运行的预览产物,非真机渲染。
其余三端没有任何实测证据,不作支持承诺。
<cu-tabs :list="longList" :current="cur" @change="onCur" @longPress="onLongPress" />
<cu-tabs :list="fourList" :current="cur2" :scrollable="false" @change="onCur2" />
<cu-tabs :list="emptyList" />
<cu-tabs :list="labelList" keyName="label" :current="cur3" :scrollable="false" @change="onCur3" />
<cu-tabs :list="disabledList" :current="cur4" :scrollable="false" @change="onCur4" @click="onClick" />
<cu-tabs :list="longTextList" :current="cur" @change="onCur" /> <cu-tabs :list="longTextList" :current="cur5" :scrollable="false" :lineWidth="12" @change="onCur5" />
<cu-tabs :list="fourList" :current="cur6" :scrollable="false" :lineWidth="60" :lineHeight="8" @change="onCur6" /> <cu-tabs :list="fourList" :current="cur6" :scrollable="false" :lineWidth="4" :lineHeight="2" @change="onCur6" />
<cu-tabs :list="fourList" :current="9" :scrollable="false" /> <cu-tabs :list="fourList" :current="-1" :scrollable="false" />
<cu-tabs :list="fourList" :current="cur7" @change="onCur7"> <template v-slot:left> <text> 左槽 </text> </template> <template v-slot:right> <text> 右槽 </text> </template> </cu-tabs>
<cu-tabs :list="fourList" :current="cur8" :scrollable="false" :duration="500" lineBgSize="contain" url="" linkType="navigateTo" @change="onCur8" />
<cu-tabs :list="fourList" :current="cur9" :scrollable="false" lineColor="red" @change="onCur9" />
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| 数据与状态 | |||
| list | 页签数据数组,每项用 name 作标题,可带 disabled 标记禁用项 | Array | (): UTSJSONObject[] => [] |
| current | 当前激活项下标;越界或负值时不激活任何项,也不显示滑块 | Number | 0 |
| keyName | 取标题的键名,默认 name;列表项改用其他键时同步改这里 | String | 'name' |
| 样式 | |||
| lineColor | 滑块颜色 | String | '#3c9cff' |
| lineWidth | 滑块宽度,按 px 落地 | Number | 20 |
| lineHeight | 滑块高度,按 px 落地 | Number | 3 |
| activeStyle | 激活项文字的内联样式,如字号与字重 | Object | (): UTSJSONObject => ({ color: '#303133' }) |
| inactiveStyle | 非激活项文字的内联样式 | Object | (): UTSJSONObject => ({ color: '#606266' }) |
| itemStyle | 每个页签项的内联样式,默认给 44px 行高 | Object | (): UTSJSONObject => ({ height: '44px' }) |
| scrollable | 为 true 时页签横向滚动;为 false 时每项平分宽度 | Boolean | true |
| 交互与样式 | |||
| customStyle | 根节点内联样式 | Object | (): UTSJSONObject => ({}) |
| customClass | 追加到根节点的类名 | String | '' |
| 声明保留但不被消费 | |||
| duration | 滑块过渡时长,毫秒;本仓不做过渡动画,传了不生效 | Number | 300 |
| lineBgSize | 滑块背景尺寸;本仓滑块是纯色块,传了不生效 | String | 'cover' |
| url | 不产生跳转,请在 @change 里自行跳转 | String | '' |
| linkType | 不产生跳转,同上 | String | 'navigateTo' |
| 事件 | 说明 | 类型 | 默认值 | 平台差异说明 |
|---|---|---|---|---|
| @click | 点任意页签项时触发,载荷 { index };禁用项也触发 | Handler | - | 各端一致 |
| @change | 点非禁用页签项时触发,载荷 { index } | Handler | - | 各端一致 |
| @longPress | 长按页签项时触发,载荷 { index };禁用项也触发 | Handler | - | 各端一致 |
| slot | 说明 |
|---|---|
| left | 页面签行最左侧的内容,如展开按钮;不填时该位不占宽度 |
| right | 页面签行最右侧的内容,如筛选按钮;不填时该位不占宽度 |
纯受控要回写 :点页签只上抛 change 的下标,组件自己不记激活项,页面不回写 current 时下划线与高亮都不会动。
滑块按像素 :滑块宽高直接按像素落地,不是 rpx 单位,同数值约是 rpx 档的两倍,传参时需按像素口径换算。