Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Vant Slider slider


May 07, 2021 Vant


Table of contents


Introduced

import Vue from 'vue';
import { Slider } from 'vant';

Vue.use(Slider);

Code demo

Basic usage

<van-slider v-model="value" @change="onChange" />
import { Toast } from 'vant';

export default {
  data() {
    return {
      value: 50
    };
  },
  methods: {
    onChange(value) {
      Toast('当前值:' + value);
    }
  }
};

Specify the selection range

<van-slider v-model="value" :min="-50" :max="50" />

Disable

<van-slider v-model="value" disabled />

Specify the step length

<van-slider v-model="value" :step="10" />

Custom styles

<van-slider
  v-model="value"
  bar-height="4px"
  active-color="#ee0a24"
/>

Custom buttons

<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>

Vertical direction

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>

Api

Props

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

Events

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 -

Slots

Name Description
button Customize the slide button


Example demonstration