element/examples/docs/en-US/slider.md

176 lines
3.7 KiB
Markdown
Raw Normal View History

<script>
export default {
data() {
return {
value1: 0,
value2: 50,
2017-03-10 14:24:04 +00:00
value3: 36,
value4: 42,
value5: 0,
2017-02-17 11:09:59 +00:00
value6: 0,
2017-03-10 14:24:04 +00:00
value7: 0,
value8: [4, 8]
};
}
}
</script>
2017-03-10 14:24:04 +00:00
## Slider
Drag the slider within a fixed range.
### Basic usage
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 14:24:04 +00:00
<el-slider v-model="value1"></el-slider>
</div>
<div class="block">
<span class="demonstration">Customized initial value</span>
<el-slider v-model="value2"></el-slider>
</div>
2017-03-10 14:24:04 +00:00
<div class="block">
<span class="demonstration">Hide Tooltip</span>
<el-slider v-model="value3" :show-tooltip="false"></el-slider>
</div>
<div class="block">
<span class="demonstration">Disabled</span>
2017-03-10 14:24:04 +00:00
<el-slider v-model="value4" disabled></el-slider>
</div>
</template>
<script>
export default {
data() {
return {
value1: 0,
value2: 50,
2017-03-10 14:24:04 +00:00
value3: 36,
value4: 42
}
}
}
</script>
```
:::
### Discrete values
The options can be discrete.
:::demo Set step size with the `step` attribute. You can display breakpoints by setting the `show-stops` attribute.
```html
<template>
<div class="block">
<span class="demonstration">Breakpoints not displayed</span>
<el-slider
2017-03-10 14:24:04 +00:00
v-model="value5"
:step="10">
2017-03-10 14:24:04 +00:00
</el-slider>
</div>
<div class="block">
<span class="demonstration">Breakpoints displayed</span>
<el-slider
2017-03-10 14:24:04 +00:00
v-model="value6"
:step="10"
show-stops>
</el-slider>
</div>
</template>
<script>
export default {
data() {
return {
2017-03-10 14:24:04 +00:00
value5: 0,
value6: 0
}
}
}
</script>
```
:::
### Slider with input box
Set value via a input box.
:::demo Set the `show-input` attribute to display an input box on the right.
```html
<template>
<div class="block">
<el-slider
2017-03-10 14:24:04 +00:00
v-model="value7"
show-input>
2017-03-10 14:24:04 +00:00
</el-slider>
</div>
</template>
<script>
export default {
data() {
return {
2017-03-10 14:24:04 +00:00
value7: 0
}
}
}
</script>
```
:::
2017-02-17 11:09:59 +00: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
2017-03-10 14:24:04 +00:00
v-model="value8"
2017-02-17 11:09:59 +00:00
range
show-stops
:max="10">
</el-slider>
</div>
</template>
<script>
export default {
data() {
return {
2017-03-10 14:24:04 +00:00
value8: [4, 8]
2017-02-17 11:09:59 +00:00
}
}
}
</script>
```
:::
## Attributes
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------------- |---------- |-------------------------------- |-------- |
| 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 11:09:59 +00:00
| show-input | whether to display an input box, works when `range` is false | boolean | — | false |
| show-input-controls | whether to display control buttons when `show-input` is true | boolean | — | true |
| show-stops | whether to display breakpoints | boolean | — | false |
2017-03-10 14:24:04 +00:00
| show-tooltip | whether to display tooltip value | boolean | — | true |
2017-02-17 11:09:59 +00:00
| range | whether to select a range | boolean | — | false |
## Events
| Event Name | Description | Parameters |
|---------- |-------- |---------- |
2016-12-31 10:16:08 +00: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 |