Skip to content

Segment 分段器

介绍

用于展示多个分段选项,用户可在选项之间进行切换。

基础用法

通过 v-model 绑定选中的值,通过 options 属性配置选项数据。

html
<vd-segment v-model="state.value" :options="state.options" />
ts
import { SegmentOption } from 'vital-design';

const state = reactive({
  value: '1',
  options: [
    { label: '测试1', value: '1' },
    { label: '测试2', value: '2' },
    { label: '测试3', value: '3' },
    { label: '测试4', value: '4' }
  ] as SegmentOption[],
});

按钮主题

通过 theme 属性可设置分段器按钮主题。

html
<vd-segment
  v-model="state.value"
  :options="state.options"
  theme="button"
/>
ts
import { SegmentOption } from 'vital-design';

const state = reactive({
  value: '1',
  options: [
    { label: '测试1', value: '1' },
    { label: '测试2', value: '2' },
    { label: '测试3', value: '3' },
    { label: '测试4', value: '4' }
  ] as SegmentOption[],
});

设置圆角

通过 radius 属性可设置分段器圆角大小。

html
<vd-segment
  v-model="state.value"
  :options="state.options"
  theme="button"
  radius="99px"
/>
ts
import { SegmentOption } from 'vital-design';

const state = reactive({
  value: '1',
  options: [
    { label: '测试1', value: '1' },
    { label: '测试2', value: '2' },
    { label: '测试3', value: '3' },
    { label: '测试4', value: '4' }
  ] as SegmentOption[],
});

自定义主题颜色

通过 theme-color 属性可设置分段器自定义主题颜色。

html
<vd-segment
  v-model="state.value"
  :options="state.options"
  theme="button"
  theme-color="#ee0a24"
/>
ts
import { SegmentOption } from 'vital-design';

const state = reactive({
  value: '1',
  options: [
    { label: '测试1', value: '1' },
    { label: '测试2', value: '2' },
    { label: '测试3', value: '3' },
    { label: '测试4', value: '4' }
  ] as SegmentOption[],
});

自定义选项图标

通过 icon 属性可设置分段器自定义选项图标。

html
<vd-segment
  v-model="state.value"
  :options="state.options"
  theme="button"
/>
ts
import { SegmentOption } from 'vital-design';

const state = reactive({
  value: 1,
  options: [
    { label: '测试1', value: 1, icon: 'home-fill' },
    { label: '测试2', value: 2, icon: 'star-fill' },
    { label: '测试3', value: 3, icon: 'cart-fill' },
    { label: '测试4', value: 4, icon: 'user-fill' }
  ] as SegmentOption[],
});

API

Props

参数说明类型默认值
v-model当前值string | number-
options选项数据SegmentOption[]-
theme主题样式SegmentTheme'default'
theme-color主题颜色string-
radius圆角大小string | number4
update-on-view当组件出现在视图时,是否自动触发更新事件booleantrue

代替原始 Props

参数说明类型默认值
custom-id根节点idstring-
custom-class根节点类名ClassValue-
custom-style根节点样式StyleValue-

Events

事件名说明回调参数
click点击时触发MouseEvent
change选中改变时触发SegmentOption

Slots

名称说明
icon图标
label标签
option选项

赣ICP备2025061025号-1