Skip to content

Slider 滑块

支持单向滑块和双向滑块,可用于在范围内选择一个值或一段区间。

组件类型

基本用法

v-model 为绑定值。值为 number 时显示一个滑块。

html
<wd-slider v-model="value" />
ts
const value = ref<number>(30)

双向滑块

设置 range 后,绑定值变为数组类型。

html
<wd-slider v-model="value" range />
ts
const value = ref<number[]>([20, 60])

组件状态

禁用状态

设置 disabled 禁用滑块。

html
<wd-slider v-model="value" disabled />

组件样式

显示极值

设置 show-extreme-value 显示最小值和最大值。

html
<wd-slider v-model="value" show-extreme-value />

管道样式

设置 theme="capsule" 使用管道样式。

html
<wd-slider v-model="value" theme="capsule" />

指定步长

通过 step 设置步长。

html
<wd-slider v-model="value" :step="10" />

指定选择范围

通过 minmax 设置取值范围。

html
<wd-slider v-model="value" :min="-10" :max="10" show-extreme-value />

刻度标记

通过 marks 配置刻度标记。

html
<wd-slider v-model="value" :marks="[0, 25, 50, 75, 100]" :step="25" />

刻度标记(管道)

刻度标记也可以与管道样式组合使用。

html
<wd-slider v-model="value" :marks="[0, 25, 50, 75, 100]" :step="25" theme="capsule" />

布局能力

垂直方向

设置 vertical 以垂直方向展示。

html
<wd-slider v-model="value" vertical />
<wd-slider v-model="rangeValue" vertical range />

垂直 + 管道

垂直方向支持与 theme="capsule" 组合使用。

html
<wd-slider v-model="value" vertical theme="capsule" />
<wd-slider v-model="rangeValue" vertical theme="capsule" range show-extreme-value />

Attributes

参数说明类型默认值
model-value / v-model当前滑块值,单滑块为 number,双滑块为 number[]SliderValue0
min最小值number0
max最大值number100
step步长number1
range是否为双向滑块模式booleanfalse
vertical是否垂直展示booleanfalse
theme滑块风格,可选值为 defaultcapsuleSliderTheme'default'
disabled是否禁用booleanfalse
show-extreme-value是否显示最小值和最大值文本booleanfalse
popover-visible气泡显示模式,可选值为 alwaysnormalneverSliderPopoverVisible'normal'
marks刻度标记,支持数组或对象形式SliderMarks-
active-color进度条激活态颜色string''
inactive-color进度条未激活态颜色string''
custom-class根节点样式类string''
custom-style根节点样式string''

Events

事件名称说明参数
dragstart开始拖动时触发{ value }
dragmove拖动过程中触发{ value }
dragend拖动结束时触发{ value }
change值变化时触发value

Methods

方法名说明参数
initSlider初始化 slider 尺寸数据-

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-slider-bar-height$n-2-
--wot-slider-bar-height-capsule$n-24轨道高度
--wot-slider-bar-bg$filled-strong胶囊轨道高度
--wot-slider-bar-radius$radius-full轨道背景色
--wot-slider-bar-height-vertical$n-248轨道圆角
--wot-slider-line-bg$primary-6-
--wot-slider-line-height$n-2进度条背景色
--wot-slider-line-height-capsule$n-18进度条高度
--wot-slider-dot-size$n-24-
--wot-slider-dot-bg$filled-oppo滑块尺寸
--wot-slider-dot-shadow0 2px 8px 0 rgba(0, 0, 0, 0.1)滑块背景色
--wot-slider-dot-popover-bg$opacfilled-tooltip-toast-cover-
--wot-slider-dot-popover-color$text-white气泡提示背景色
--wot-slider-dot-popover-radius$radius-main气泡提示文字颜色
--wot-slider-dot-popover-padding$padding-extra-tight $padding-loose气泡提示圆角
--wot-slider-dot-popover-font-size$typography-body-size-main气泡提示内边距
--wot-slider-dot-popover-line-height$typography-body-line-height-size-main气泡提示文字字号
--wot-slider-dot-popover-gap$n-3气泡提示行高
--wot-slider-dot-popover-arrow-width$n-12气泡提示与滑块间距
--wot-slider-dot-popover-arrow-height$n-6气泡提示箭头宽度
--wot-slider-dot-popover-duration-exit100ms气泡提示箭头高度
--wot-slider-dot-popover-easing-exitcubic-bezier(0.4, 0, 1, 1)气泡提示离场动画时长
--wot-slider-dot-popover-duration-enter200ms气泡提示离场动画缓动
--wot-slider-dot-popover-easing-entercubic-bezier(0.34, 1.56, 0.64, 1)气泡提示入场动画时长
--wot-slider-scale-size$n-6-
--wot-slider-scale-border-radius$radius-full刻度尺寸
--wot-slider-scale-bg$filled-strong刻度圆角
--wot-slider-scale-bg-active$primary-6刻度背景色
--wot-slider-scale-capsule-bg$filled-strong激活刻度背景色
--wot-slider-scale-capsule-width$n-2胶囊刻度背景色
--wot-slider-scale-capsule-border-radius$radius-zero胶囊刻度宽度
--wot-slider-scale-desc-font-size$typography-body-size-main胶囊刻度圆角
--wot-slider-scale-desc-line-height$typography-body-line-height-size-main刻度描述文字字号
--wot-slider-scale-desc-color$text-main刻度描述行高
--wot-slider-scale-desc-spacing$spacing-tight刻度描述文字颜色
--wot-slider-marks-desc-spacingcalc($slider-dot-size / 2 + $spacing-tight)刻度描述间距
--wot-slider-marks-desc-capsule-spacingcalc($slider-dot-size + $spacing-super-tight)标记描述间距
--wot-slider-marks-extra-padding$padding-super-loose胶囊标记描述间距
--wot-slider-marks-extra-capsule-padding$padding-ultra-loose标记额外内边距
--wot-slider-capsule-track-inset$n-3-
--wot-slider-extreme-spacing$spacing-loose胶囊轨道内缩距离
--wot-slider-value-font-size$typography-body-size-main-
--wot-slider-value-color$text-secondary极值文字字号
--wot-slider-opacity-disabled$opacity-disabled-

源代码

文档
组件

Released under the MIT License.

Released under the MIT License.