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-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-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.