Slider
This component is used to select one or more values within a given range, commonly used for volume control, brightness adjustment, price range filtering, and similar scenarios.
- Supports single value selection and range selection
- Supports step size and tick mark display
- Supports vertical mode
- Customizable slider track colors
Notice
This component may have slight differences in appearance across platforms. Please refer to the actual effect.
Platform Differences
| App (vue) | App (nvue) | H5 | Mini Program |
|---|---|---|---|
| √ | √ | √ | √ |
Basic Usage
- Bind the slider value via
v-model, default value is0. - Set the value range via
minandmax, default is0to100.
html
<see-slider v-model="value" />
<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(30);
</script>1
2
3
4
5
6
2
3
4
5
6
Range Selection
- Set
isRangetotrueto enable range selection mode. - In this mode, the
v-modelbinding value should be an array, such as[20, 80].
html
<see-slider v-model="value" isRange />
<script lang="ts" setup>
import { ref } from 'vue';
const value = ref([20, 80]);
</script>1
2
3
4
5
6
2
3
4
5
6
Step and Tick Marks
- Set the step size via
step. - Set
isShowSteptotrueto display tick marks.
html
<see-slider v-model="value" :step="10" isShowStep />
<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(40);
</script>1
2
3
4
5
6
2
3
4
5
6
Show Current Value
- Set
isShowValuetotrueto display the current value next to the slider thumb.
html
<see-slider v-model="value" isShowValue />
<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(50);
</script>1
2
3
4
5
6
2
3
4
5
6
Vertical Mode
- Set
isVerticaltotrueto switch to vertical mode.
html
<see-slider v-model="value" isVertical style="height: 200px;" />
<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(30);
</script>1
2
3
4
5
6
2
3
4
5
6
Custom Colors
- Set the active track color via
activeColor. - Set the inactive track color via
inactiveColor.
html
<see-slider v-model="value" activeColor="#07c160" inactiveColor="#eee" />
<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(60);
</script>1
2
3
4
5
6
2
3
4
5
6
Disabled State
- Set
isDisabledtotrueto disable the slider. - In disabled state, drag events will not trigger, and the style will turn gray or reduce in transparency.
html
<see-slider v-model="value" isDisabled />
<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(50);
</script>1
2
3
4
5
6
2
3
4
5
6
Readonly State
- Set
isReadonlytotrueto set the slider to readonly state. - In readonly state, drag events will not trigger, but the style remains unchanged.
html
<see-slider v-model="value" isReadonly />
<script lang="ts" setup>
import { ref } from 'vue';
const value = ref(50);
</script>1
2
3
4
5
6
2
3
4
5
6
API
Props
| Parameter | Description | Type | Default | Optional Values | Platform Notes |
|---|---|---|---|---|---|
| modelValue | Binding value | number | number[] | 0 | - | - |
| min | Minimum value | number | 0 | - | - |
| max | Maximum value | number | 100 | - | - |
| step | Step size | number | 1 | Any positive number | - |
| isDisabled | Whether disabled | boolean | false | true, false | - |
| isReadonly | Whether readonly | boolean | false | true, false | - |
| isRange | Whether it is range selection | boolean | false | true, false | - |
| isVertical | Whether it is vertical mode | boolean | false | true, false | - |
| barHeight | Track height (px) | number | 4 | Any positive number | - |
| activeColor | Active track color | string | - | Any CSS color value | - |
| inactiveColor | Inactive track color | string | - | Any CSS color value | - |
| isShowValue | Whether to show current value | boolean | false | true, false | - |
| isShowStep | Whether to show tick marks | boolean | false | true, false | - |
| size | Size | "small" | "default" | "large" | 'default' | small, default, large | - |
| name | Form field name | string | '' | - | - |
Events
| Event Name | Description | Callback Parameters |
|---|---|---|
| onChange | Triggered when value changes | value: Current value |
| onDragStart | Triggered when starting to drag the slider thumb | value: Current value |
| onDragEnd | Triggered when ending drag of the slider thumb | value: Current value |
