01
受控
<cu-subsection :list="three" :current="curNow" @change="onChange" />
分段器用于在少量互斥选项间切换,常放在列表顶部做排序或筛选。
整目录放进工程即用: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-subsection /> # 4 单个组件也可以显式引入(可选,不用 easycom 时) import CuSubsection from '@/uni_modules/colorui-x/components/cu-subsection/cu-subsection.uvue'
组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。
| Android | iOS | HarmonyOS | Web(H5) | 微信小程序 | 支付宝小程序 |
|---|---|---|---|---|---|
| √ | — | — | √ | — | — |
Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。
Web 列只表示已编出可运行的预览产物,非真机渲染。
其余三端没有任何实测证据,不作支持承诺。
<cu-subsection :list="three" :current="curNow" @change="onChange" />
<cu-subsection :list="three" :current="1" mode="button" /> <cu-subsection :list="three" :current="1" mode="subsection" /> <cu-subsection :list="three" :current="1" mode="tab" />
<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" />
<cu-subsection :list="three" :fontSize="0" /> <cu-subsection :list="three" :fontSize="10" /> <cu-subsection :list="three" /> <cu-subsection :list="three" :fontSize="18" />
<cu-subsection :list="three" :current="1" :bold="true" /> <cu-subsection :list="three" :current="1" :bold="false" />
<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="" />
<cu-subsection :list="one" :current="0" /> <cu-subsection :list="two" :current="1" /> <cu-subsection :list="five" :current="2" /> <cu-subsection :list="empty" />
<cu-subsection :list="longText" :current="1" /> <cu-subsection :list="longText" :current="1" mode="subsection" />
<cu-subsection :list="three" :customStyle="blockStyle" /> <cu-subsection :list="three" customClass="custom-class" :keyName="labelKey" />
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| 选项与选中 | |||
| list | 各分段文案;元素一律按字符串收口,对象数组取不到值 | Array | (): string[] => [] |
| current | 当前选中项下标,从 0 起;纯受控,点分段只上抛事件,滑块位置恒等于该值 | Number | 0 |
| mode | button / subsection,样式档;前者为白底滑块,后者为描边加分色滑块 | String | 'button' |
| fontSize | 分段文字字号,px 契约值;运行时 ×2 换算成 rpx(12 → 24rpx) | Number | 12 |
| bold | 选中项是否加粗 | Boolean | true |
| 配色与样式 | |||
| activeColor | 选中项文字色与描边色;subsection 档下兼作滑块底色 | String | '#3c9cff' |
| inactiveColor | 未选中项文字色 | String | '#303133' |
| bgColor | 分段条底色;仅 button 档生效 | String | '#eeeeef' |
| customStyle | 根节点内联样式 | Object | (): UTSJSONObject => ({}) |
| customClass | 追加到根节点的类名 | String | '' |
| 声明保留但不被消费 | |||
| keyName | 从对象数组取文案的键名;本仓只收字符串数组,该键不读取 | String | 'name' |
| url | 不产生跳转,传参不生效 | String | '' |
| linkType | 不产生跳转,同上 | String | 'navigateTo' |
| 事件 | 说明 | 类型 | 默认值 | 平台差异说明 |
|---|---|---|---|---|
| @change | 点击分段时触发,载荷为被点项下标;需页面把新下标写回 current | Handler | - | 各端一致 |
本件没有插槽。
纯受控回写 :点分段只上抛下标,滑块位置恒等于 current,不在页面把新下标写回就停在原选项,表现为点了没反应。
越界滑块飞出 :下标不做夹取,超过项数时滑块会按倍数移出可视区,只剩文字没有选中块,传给它的值要先自己校验范围。