Skip to content

Slider 滑块

通过拖动滑块在一个固定区间内进行选择

基础用法

在拖动滑块时,显示当前值

通过设置绑定值自定义滑块的初始值

Default value
Customized initial value
Details
vue
<template>
  <div class="list">
    <div class="item">
      <span>Default value</span> <a-slider v-model="value1" />
    </div>
    <div class="item">
      <span>Customized initial value</span> <a-slider v-model="value2" />
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
const value1 = ref(0);
const value2 = ref(50);
</script>

<style lang="less" scoped>
.list {
  .item {
    display: flex;
    align-items: center;
    span {
      min-width: 200px;
      font-size: 13.5px;
    }
  }
}
</style>

离散值

选项可以是离散的

改变step的值可以改变步长, 通过设置 show-stops 属性可以显示间断点

step
stops
Details
vue
<template>
    <div class="list">
      <div class="item">
        <span>step </span> <a-slider v-model="value1" :step="5" />
      </div>
      <div class="item">
        <span>stops</span> <a-slider show-stops  v-model="value2" :step="10" />
      </div>
    </div>
  </template>
  
  <script lang="ts" setup>
  import { ref } from "vue";
  const value1 = ref(10);
  const value2 = ref(30);
  </script>
  
  <style lang="less" scoped>
  .list {
    .item {
      display: flex;
      align-items: center;
      span {
        min-width: 100px;
        font-size: 13.5px;
      }
    }
  }
  </style>

带有输入框的滑块

通过输入框输入来改变当前的值。

设置 show-input 属性会在右侧显示一个输入框

Details
vue
<template>
    <a-slider v-model="value1" show-input />
  </template>
  
  <script lang="ts" setup>
  import { ref } from "vue";
  const value1 = ref(10);
  </script>
  
  <style lang="less" scoped>
  .list {
    .item {
      display: flex;
      align-items: center;
      span {
        min-width: 200px;
        font-size: 13.5px;
      }
    }
  }
  </style>

Slider API

属性名说明类型默认值
v-modelslider 绑定的值number0
step步长number1
show-stops是否显示间断点booleanfalse
show-input是否显示输入框booleanfalse

Slider Events

事件名说明回调参数
change当选中值发生变化时触发val,目前的选中值