组件 / 导航 / cu-subsection 分段器

cu-subsection

分段器用于在少量互斥选项间切换,常放在列表顶部做排序或筛选。

01 / Install

引入组件

整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。

install
# 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-subsection />

# 4  单个组件也可以显式引入(可选,不用 easycom 时)
import CuSubsection from '@/uni_modules/colorui-x/components/cu-subsection/cu-subsection.uvue'

组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。

02 / Platform

平台支持

AndroidiOSHarmonyOSWeb(H5)微信小程序支付宝小程序
√ — — √ — —

Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。

Web 列只表示已编出可运行的预览产物,非真机渲染。

其余三端没有任何实测证据,不作支持承诺。

03 / Demo

代码演示

01

受控

uvue
<cu-subsection :list="three" :current="curNow" @change="onChange" />
02

模式

uvue
<cu-subsection :list="three" :current="1" mode="button" />
<cu-subsection :list="three" :current="1" mode="subsection" />
<cu-subsection :list="three" :current="1" mode="tab" />
03

当前项

uvue
<cu-subsection :list="three" :current="0" mode="subsection" />
<cu-subsection :list="three" :current="1" mode="subsection" />
<cu-subsection :list="three" :current="2" mode="subsection" />
<cu-subsection :list="three" :current="9" />
04

字号

uvue
<cu-subsection :list="three" :fontSize="0" />
<cu-subsection :list="three" :fontSize="10" />
<cu-subsection :list="three" />
<cu-subsection :list="three" :fontSize="18" />
05

加粗

uvue
<cu-subsection :list="three" :current="1" :bold="true" />
<cu-subsection :list="three" :current="1" :bold="false" />
06

颜色

uvue
<cu-subsection :list="three" activeColor="#e54d42" inactiveColor="#39b54a" bgColor="#f37b1d" />
<cu-subsection :list="three" mode="subsection" activeColor="#6739b6" inactiveColor="#ff3030" />
<cu-subsection :list="three" activeColor="" inactiveColor="" bgColor="" />
07

项数

uvue
<cu-subsection :list="one" :current="0" />
<cu-subsection :list="two" :current="1" />
<cu-subsection :list="five" :current="2" />
<cu-subsection :list="empty" />
08

超长文案

uvue
<cu-subsection :list="longText" :current="1" />
<cu-subsection :list="longText" :current="1" mode="subsection" />
09

自定义 / 未消费

uvue
<cu-subsection :list="three" :customStyle="blockStyle" />
<cu-subsection :list="three" customClass="custom-class" :keyName="labelKey" />
10

取值与事件

这一节的交互由演示页脚本驱动,效果见右侧实时预览。

04 / Props · Events · Slots

全量 API

props

参数说明类型默认值
选项与选中
list各分段文案;元素一律按字符串收口,对象数组取不到值Array(): string[] => []
current当前选中项下标,从 0 起;纯受控,点分段只上抛事件,滑块位置恒等于该值Number0
modebutton / subsection,样式档;前者为白底滑块,后者为描边加分色滑块String'button'
fontSize分段文字字号,px 契约值;运行时 ×2 换算成 rpx(12 → 24rpx)Number12
bold选中项是否加粗Booleantrue
配色与样式
activeColor选中项文字色与描边色;subsection 档下兼作滑块底色String'#3c9cff'
inactiveColor未选中项文字色String'#303133'
bgColor分段条底色;仅 button 档生效String'#eeeeef'
customStyle根节点内联样式Object(): UTSJSONObject => ({})
customClass追加到根节点的类名String''
声明保留但不被消费
keyName从对象数组取文案的键名;本仓只收字符串数组,该键不读取String'name'
url不产生跳转,传参不生效String''
linkType不产生跳转,同上String'navigateTo'

events

事件说明类型默认值平台差异说明
@change点击分段时触发,载荷为被点项下标;需页面把新下标写回 currentHandler-各端一致

slots

本件没有插槽。

05 / Notes

注意事项

纯受控回写 :点分段只上抛下标,滑块位置恒等于 current,不在页面把新下标写回就停在原选项,表现为点了没反应。

越界滑块飞出 :下标不做夹取,超过项数时滑块会按倍数移出可视区,只剩文字没有选中块,传给它的值要先自己校验范围。