Slider 滑动输入条

滑动型输入器,展示当前值和可选范围。

何时使用

当用户需要在数值区间/自定义区间内进行选择时,可为连续或离散值。

代码演示

Disabled:

基本

基本滑动条。当 rangetrue 时,渲染为双滑块。当 disabledtrue 时,滑块处于不可用状态。

expand code expand code

带输入框的滑块

数字输入框 组件保持同步。

expand code expand code

带 icon 的滑块

滑块左右可以设置图标来表达业务含义。

expand code expand code

自定义提示

使用 tipFormatter 可以格式化 Tooltip 的内容,设置 tipFormatter={null},则隐藏 Tooltip

expand code expand code

事件

当 Slider 的值发生改变时,会触发 onChange 事件,并把改变后的值作为参数传入。在 onmouseup 时,会触发 onAfterChange 事件,并把当前值作为参数传入。

expand code expand code

included=true

0°C26°C37°C100°C
0°C26°C37°C100°C

included=false

0°C26°C37°C100°C

marks & step

0°C26°C37°C100°C

step=null

0°C26°C37°C100°C

带标签的滑块

使用 marks 属性标注分段式滑块,使用 value / defaultValue 指定滑块位置。当 included=false 时,表明不同标记间为并列关系。当 step=null 时,Slider 的可选值仅有 marks 标出来的部分。

expand code expand code
0°C26°C37°C100°C

垂直

垂直方向的 Slider。

expand code expand code

控制 ToolTip 的显示

tooltipVisibletrue 时,将始终显示ToolTip;反之则始终不显示,即使在拖动、移入时也是如此。

expand code expand code

API

参数 说明 类型 默认值
autoFocus 自动获取焦点 boolean false
defaultValue 设置初始取值。当 rangefalse 时,使用 number,否则用 [number, number] number|number[] 0 or [0, 0]
disabled 值为 true 时,滑块为禁用状态 boolean false
dots 是否只能拖拽到刻度上 boolean false
included marks 不为空对象时有效,值为 true 时表示值为包含关系,false 表示并列 boolean true
marks 刻度标记,key 的类型必须为 number 且取值在闭区间 [min, max] 内,每个标签可以单独设置样式 object { number: string|VNode } or { number: { style: object, label: string|VNode } } or { number: () => VNode }
max 最大值 number 100
min 最小值 number 0
range 双滑块模式 boolean false
step 步长,取值必须大于 0,并且可被 (max - min) 整除。当 marks 不为空对象时,可以设置 stepnull,此时 Slider 的可选值仅有 marks 标出来的部分。 number|null 1
tipFormatter Slider 会把当前值传给 tipFormatter,并在 Tooltip 中显示 tipFormatter 的返回值,若为 null,则隐藏 Tooltip。 Function|null IDENTITY
value(v-model) 设置当前取值。当 rangefalse 时,使用 number,否则用 [number, number] number|number[]
vertical 值为 true 时,Slider 为垂直方向 Boolean false
tooltipVisible 值为true时,Tooltip 将会始终显示;否则始终不显示,哪怕在拖拽及移入时。 Boolean

事件

事件名称 说明 回调参数
afterChange mouseup 触发时机一致,把当前值作为参数传入。 Function(value)
change 当 Slider 的值发生改变时,会触发 change 事件,并把改变后的值作为参数传入。 Function(value)

方法

名称 描述
blur() 移除焦点
focus() 获取焦点
  Select 选择器Switch 开关