FxSegmented 分段控制器
展示多个选项并允许用户选择其一。不依赖任何 UI 框架,选中项带滑动高亮指示,颜色走 @fx/styles 的 --color-* token,亮暗自动跟随。
基础用法
用 v-model 绑定当前选中项的值,options 为选项数组(基础类型或对象)。
尺寸
通过 size 属性设置 large / default / small 三种尺寸。
排列方向
通过 direction 设置 horizontal(水平,默认)或 vertical(垂直)。
禁用
将分段控制器整体 disabled,或单独设置某个选项的 disabled 为 true。
自定义别名
当 options 的字段名与默认(value / label / disabled)不同时,可通过 props 属性配置别名。
撑满父容器
设置 block 为 true 时,分段控制器宽度撑满父元素,各项均分宽度。
自定义内容
通过默认插槽自定义选项渲染,插槽作用域提供当前选项对象 item。
自定义样式
通过覆盖组件暴露的 CSS 变量自定义样式(如选中项颜色、圆角等)。
API
Attributes
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| model-value (v-model) | 绑定值 | string / number / boolean | — |
| options | 选项数据 | Option[] | [] |
| props | 别名配置,见下表 | object | 见下表 |
| size | 尺寸 | 'large' | 'default' | 'small' | — |
| block | 是否撑满父容器宽度 | boolean | false |
| disabled | 是否禁用 | boolean | false |
| validate-event | 是否在值变化时触发表单项校验 | boolean | true |
| name | 原生 name(radio 分组名,未传则自动生成) | string | — |
| id | 原生 id | string | — |
| aria-label | 原生 aria-label | string | — |
| direction | 排列方向 | 'horizontal' | 'vertical' | horizontal |
自定义别名
props 属性的配置项,用于指定对象选项中取值 / 标签 / 禁用标记对应的字段名。
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| value | 用作选项值的字段名 | string | value |
| label | 用作选项标签的字段名 | string | label |
| disabled | 用作禁用标记的字段名 | string | disabled |
Events
| 事件名 | 说明 | 类型 |
|---|---|---|
| update:model-value | 值更新时触发 | (value: string | number | boolean) => void |
| change | 选中值变化时触发,参数为当前值 | (value: string | number | boolean) => void |
Slots
| 插槽名 | 说明 | 类型 |
|---|---|---|
| default | 自定义选项内容 | { item: Option } |
类型声明
展开查看
ts
type Option = Record<string, any> | string | number | boolean