May 07, 2021 Vant
import Vue from 'vue';
import { Slider } from 'vant';
Vue.use(Slider);
<van-slider v-model="value" @change="onChange" />
import { Toast } from 'vant';
export default {
data() {
return {
value: 50
};
},
methods: {
onChange(value) {
Toast('当前值:' + value);
}
}
};
<van-slider v-model="value" :min="-50" :max="50" />
<van-slider v-model="value" disabled />
<van-slider v-model="value" :step="10" />
<van-slider
v-model="value"
bar-height="4px"
active-color="#ee0a24"
/>
<van-slider v-model="value" active-color="#ee0a24">
<div slot="button" class="custom-button">
{{ value }}
</div>
</van-slider>
<style>
.custom-button {
width: 26px;
color: #fff;
font-size: 10px;
line-height: 18px;
text-align: center;
background-color: #ee0a24;
border-radius: 100px;
}
</style>
When slider is displayed vertically, the height is 100% the height of the parent element
<div :style="{ height: '100px' }">
<van-slider v-model="value" vertical />
</div>
Parameters | Description | Type | The default |
---|---|---|---|
value | The percentage of the current progress | number |
0
|
max | The maximum value | number | string |
100
|
min | The minimum value | number | string |
0
|
step | Step | number | string |
1
|
bar-height |
Progress bar height, the default unit
px
|
number | string |
2px
|
button-size
v2.4.5
|
Slider button size, the default unit
px
|
number | string |
24px
|
active-color | The progress bar activates the state color | string |
#1989fa
|
inactive-color | The progress bar inactive state color | string |
#e5e5e5
|
disabled | Whether to disable the slider | boolean |
false
|
vertical | Whether to display vertically | boolean |
false
|
The name of the event | Description | Callback parameters |
---|---|---|
input | Triggered in real time when progress changes | Value: Current progress |
change | The progress changes and is triggered when the drag ends | Value: Current progress |
drag-start | Triggered when you start dragging | - |
drag-end | Triggered at the end of the drag | - |
Name | Description |
---|---|
button | Customize the slide button |