2017-03-10 22:24:04 +08:00
|
|
|
|
## Slider
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|
2016-11-11 19:06:27 +08:00
|
|
|
|
Drag the slider within a fixed range.
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|
2016-11-11 19:06:27 +08:00
|
|
|
|
### Basic usage
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|
|
|
|
|
The current value is displayed when the slider is being dragged.
|
|
|
|
|
|
|
|
|
|
:::demo Customize the initial value of the slider by setting the binding value.
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<div class="block">
|
|
|
|
|
<span class="demonstration">Default value</span>
|
2017-03-10 22:24:04 +08:00
|
|
|
|
<el-slider v-model="value1"></el-slider>
|
2016-11-10 21:46:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
<div class="block">
|
|
|
|
|
<span class="demonstration">Customized initial value</span>
|
|
|
|
|
<el-slider v-model="value2"></el-slider>
|
|
|
|
|
</div>
|
2017-03-10 22:24:04 +08:00
|
|
|
|
<div class="block">
|
|
|
|
|
<span class="demonstration">Hide Tooltip</span>
|
|
|
|
|
<el-slider v-model="value3" :show-tooltip="false"></el-slider>
|
|
|
|
|
</div>
|
2017-04-04 15:40:39 +08:00
|
|
|
|
<div class="block">
|
|
|
|
|
<span class="demonstration">Format Tooltip</span>
|
|
|
|
|
<el-slider v-model="value4" :format-tooltip="formatTooltip"></el-slider>
|
|
|
|
|
</div>
|
2016-11-11 19:06:27 +08:00
|
|
|
|
<div class="block">
|
|
|
|
|
<span class="demonstration">Disabled</span>
|
2017-04-04 15:40:39 +08:00
|
|
|
|
<el-slider v-model="value5" disabled></el-slider>
|
2016-11-11 19:06:27 +08:00
|
|
|
|
</div>
|
2016-11-10 21:46:55 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
value1: 0,
|
2016-11-11 19:06:27 +08:00
|
|
|
|
value2: 50,
|
2017-03-10 22:24:04 +08:00
|
|
|
|
value3: 36,
|
2017-04-04 15:40:39 +08:00
|
|
|
|
value4: 48,
|
|
|
|
|
value5: 42
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
formatTooltip(val) {
|
|
|
|
|
return val / 100;
|
2016-11-10 21:46:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2016-11-11 19:06:27 +08:00
|
|
|
|
### Discrete values
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|
|
|
|
|
The options can be discrete.
|
|
|
|
|
|
2016-11-11 19:06:27 +08:00
|
|
|
|
:::demo Set step size with the `step` attribute. You can display breakpoints by setting the `show-stops` attribute.
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<div class="block">
|
2016-11-11 19:06:27 +08:00
|
|
|
|
<span class="demonstration">Breakpoints not displayed</span>
|
2016-11-10 21:46:55 +08:00
|
|
|
|
<el-slider
|
2019-04-19 16:02:01 +08:00
|
|
|
|
v-model="value1"
|
2016-11-10 21:46:55 +08:00
|
|
|
|
:step="10">
|
2017-03-10 22:24:04 +08:00
|
|
|
|
</el-slider>
|
2016-11-10 21:46:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
<div class="block">
|
2016-11-11 19:06:27 +08:00
|
|
|
|
<span class="demonstration">Breakpoints displayed</span>
|
2016-11-10 21:46:55 +08:00
|
|
|
|
<el-slider
|
2019-04-19 16:02:01 +08:00
|
|
|
|
v-model="value2"
|
2016-11-10 21:46:55 +08:00
|
|
|
|
:step="10"
|
|
|
|
|
show-stops>
|
|
|
|
|
</el-slider>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2019-04-19 16:02:01 +08:00
|
|
|
|
value1: 0,
|
|
|
|
|
value2: 0
|
2016-11-10 21:46:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2016-11-11 19:06:27 +08:00
|
|
|
|
### Slider with input box
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|
2016-11-11 19:06:27 +08:00
|
|
|
|
Set value via a input box.
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|
2016-11-11 19:06:27 +08:00
|
|
|
|
:::demo Set the `show-input` attribute to display an input box on the right.
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<div class="block">
|
|
|
|
|
<el-slider
|
2019-04-19 16:02:01 +08:00
|
|
|
|
v-model="value"
|
2016-11-10 21:46:55 +08:00
|
|
|
|
show-input>
|
2017-03-10 22:24:04 +08:00
|
|
|
|
</el-slider>
|
2016-11-10 21:46:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2019-04-19 16:02:01 +08:00
|
|
|
|
value: 0
|
2016-11-10 21:46:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2017-02-17 19:09:59 +08:00
|
|
|
|
### Range selection
|
|
|
|
|
|
|
|
|
|
Selecting a range of values is supported.
|
|
|
|
|
|
|
|
|
|
:::demo Setting the `range` attribute activates range mode, where the binding value is an array made up of two boundary values.
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<div class="block">
|
|
|
|
|
<el-slider
|
2019-04-19 16:02:01 +08:00
|
|
|
|
v-model="value"
|
2017-02-17 19:09:59 +08:00
|
|
|
|
range
|
|
|
|
|
show-stops
|
|
|
|
|
:max="10">
|
|
|
|
|
</el-slider>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2019-04-19 16:02:01 +08:00
|
|
|
|
value: [4, 8]
|
2017-02-17 19:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2017-04-11 13:44:54 +08:00
|
|
|
|
### Vertical mode
|
|
|
|
|
|
2017-04-27 08:28:38 +08:00
|
|
|
|
:::demo Setting the `vertical` attribute to `true` enables vertical mode. In vertical mode, the `height` attribute is required.
|
2017-04-11 13:44:54 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<div class="block">
|
|
|
|
|
<el-slider
|
2019-04-19 16:02:01 +08:00
|
|
|
|
v-model="value"
|
2017-04-11 13:44:54 +08:00
|
|
|
|
vertical
|
2017-04-27 08:28:38 +08:00
|
|
|
|
height="200px">
|
2017-04-11 13:44:54 +08:00
|
|
|
|
</el-slider>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2019-04-19 16:02:01 +08:00
|
|
|
|
value: 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
|
|
|
|
### Show marks
|
|
|
|
|
|
|
|
|
|
:::demo Setting this `marks` attribute can show mark on slider.
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<div class="block">
|
|
|
|
|
<el-slider
|
|
|
|
|
v-model="value"
|
|
|
|
|
range
|
|
|
|
|
:marks="marks">
|
|
|
|
|
</el-slider>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
value: [30, 60],
|
|
|
|
|
marks: {
|
|
|
|
|
0: '0°C',
|
|
|
|
|
8: '8°C',
|
|
|
|
|
37: '37°C',
|
|
|
|
|
50: {
|
|
|
|
|
style: {
|
|
|
|
|
color: '#1989FA'
|
|
|
|
|
},
|
|
|
|
|
label: this.$createElement('strong', '50%')
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-11 13:44:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2016-11-10 21:46:55 +08:00
|
|
|
|
## Attributes
|
2016-11-11 19:06:27 +08:00
|
|
|
|
| Attribute | Description | Type | Accepted Values | Default |
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
2019-01-23 11:34:19 +08:00
|
|
|
|
| value / v-model | binding value | number | — | 0 |
|
2016-11-11 19:06:27 +08:00
|
|
|
|
| min | minimum value | number | — | 0 |
|
|
|
|
|
| max | maximum value | number | — | 100 |
|
|
|
|
|
| disabled | whether Slider is disabled | boolean | — | false |
|
|
|
|
|
| step | step size | number | — | 1 |
|
2017-02-17 19:09:59 +08:00
|
|
|
|
| show-input | whether to display an input box, works when `range` is false | boolean | — | false |
|
2017-01-10 10:48:09 +08:00
|
|
|
|
| show-input-controls | whether to display control buttons when `show-input` is true | boolean | — | true |
|
2018-03-14 10:52:44 +08:00
|
|
|
|
| input-size | size of the input box | string | large / medium / small / mini | small |
|
2016-11-11 19:06:27 +08:00
|
|
|
|
| show-stops | whether to display breakpoints | boolean | — | false |
|
2017-03-10 22:24:04 +08:00
|
|
|
|
| show-tooltip | whether to display tooltip value | boolean | — | true |
|
2017-10-18 18:31:03 +08:00
|
|
|
|
| format-tooltip | format to display tooltip value | function(value) | — | — |
|
2017-02-17 19:09:59 +08:00
|
|
|
|
| range | whether to select a range | boolean | — | false |
|
2017-04-11 13:44:54 +08:00
|
|
|
|
| vertical | vertical mode | boolean | — | false |
|
2017-10-18 18:31:03 +08:00
|
|
|
|
| height | Slider height, required in vertical mode | string | — | — |
|
|
|
|
|
| label | label for screen reader | string | — | — |
|
2018-03-01 17:21:31 +08:00
|
|
|
|
| debounce | debounce delay when typing, in milliseconds, works when `show-input` is true | number | — | 300 |
|
|
|
|
|
| tooltip-class | custom class name for the tooltip | string | — | — |
|
2019-04-19 16:02:01 +08:00
|
|
|
|
| marks | marks, type of key must be `number` and must in closed interval `[min, max]`, each mark can custom style| object | — | — |
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|
|
|
|
|
## Events
|
2016-11-11 19:06:27 +08:00
|
|
|
|
| Event Name | Description | Parameters |
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|---------- |-------- |---------- |
|
2016-12-31 18:16:08 +08:00
|
|
|
|
| change | triggers when the value changes (if the mouse is being dragged, this event only fires when the mouse is released) | value after changing |
|
2016-11-10 21:46:55 +08:00
|
|
|
|
|