# Slider ### Install ```js import { createApp } from 'vue'; import { Slider } from 'vant'; const app = createApp(); app.use(Slider); ``` ## Usage ### Basic Usage ```html ``` ```js import { ref } from 'vue'; import { Toast } from 'vant'; export default { setup() { const value = ref(50); const onChange = (value) => Toast('Current value: ' + value); return { value, onChange, }; }, }; ``` ### Dual thumb Add `range` attribute to open dual thumb mode. ```html ``` ```js import { ref } from 'vue'; import { Toast } from 'vant'; export default { setup() { // value must be an Array const value = ref([10, 50]); const onChange = (value) => Toast('Current value: ' + value); return { value, onChange, }; }, }; ``` ### Range ```html ``` ### Disabled ```html ``` ### Step size ```html ``` ### Custom style ```html ``` ### Custom button ```html ``` ### Vertical ```html
``` ```js import { ref } from 'vue'; import { Toast } from 'vant'; export default { setup() { const value = ref(50); const value2 = ref([10, 50]); const onChange = (value) => Toast('Current value: ' + value); return { value, value2, onChange, }; }, }; ``` ## API ### Props | Attribute | Description | Type | Default | | --- | --- | --- | --- | | v-model | Current value | _number \| number[]_ | `0` | | max | Max value | _number \| string_ | `100` | | min | Min value | _number \| string_ | `0` | | step | Step size | _number \| string_ | `1` | | bar-height | Height of bar | _number \| string_ | `2px` | | button-size | Button size | _number \| string_ | `24px` | | active-color | Active color of bar | _string_ | `#1989fa` | | inactive-color | Inactive color of bar | _string_ | `#e5e5e5` | | range | Whether to enable dual thumb mode | _boolean_ | `false` | | disabled | Whether to disable slider | _boolean_ | `false` | | readonly `v3.0.5` | Whether to be readonly | _boolean_ | `false` | | vertical | Whether to display slider vertically | _boolean_ | `false` | ### Events | Event | Description | Arguments | | ------------------ | ------------------------------ | ------------------- | | update:model-value | Emitted when value is changing | value: current rate | | change | Emitted after value changed | value: current rate | | drag-start | Emitted when start draging | - | | drag-end | Emitted when end draging | - | ### Slots | Name | Description | | ------ | ------------- | | button | Custom button | ### Less Variables How to use: [Custom Theme](#/en-US/theme). | Name | Default Value | Description | | --- | --- | --- | | @slider-active-background-color | `@blue` | - | | @slider-inactive-background-color | `@gray-3` | - | | @slider-disabled-opacity | `@disabled-opacity` | - | | @slider-bar-height | `2px` | - | | @slider-button-width | `24px` | - | | @slider-button-height | `24px` | - | | @slider-button-border-radius | `50%` | - | | @slider-button-background-color | `@white` | - | | @slider-button-box-shadow | `0 1px 2px rgba(0, 0, 0, 0.5)` | - |