Skip to content
On this page

滑块组件 Slider

基础用法

<template>
  <div>
    <b-slider v-model="value1"></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value2" range></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value3" range disabled></b-slider>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref(25)
const value2 = ref([20, 60])
const value3 = ref([30, 40])
</script>
<template>
  <div>
    <b-slider v-model="value1"></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value2" range></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value3" range disabled></b-slider>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref(25)
const value2 = ref([20, 60])
const value3 = ref([30, 40])
</script>

步长和断点

<template>
  <div>
    <b-slider v-model="value4" :step="10"></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value5" :step="10" show-stops></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value6" :step="10" range></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value7" :step="10" range show-stops></b-slider>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value4 = ref(30)
const value5 = ref(35)
const value6 = ref([20, 40])
const value7 = ref([30, 50])
</script>
<template>
  <div>
    <b-slider v-model="value4" :step="10"></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value5" :step="10" show-stops></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value6" :step="10" range></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value7" :step="10" range show-stops></b-slider>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value4 = ref(30)
const value5 = ref(35)
const value6 = ref([20, 40])
const value7 = ref([30, 50])
</script>

输入框

<template>
  <div>
    <b-slider v-model="value1" show-input></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value2" :format-tooltip="format"></b-slider>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref(25)
const value2 = ref(35)

function format(val) {
  return '进度: ' + val + '%'
}
</script>
<template>
  <div>
    <b-slider v-model="value1" show-input></b-slider>
    <div class="p10"></div>
    <b-slider v-model="value2" :format-tooltip="format"></b-slider>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref(25)
const value2 = ref(35)

function format(val) {
  return '进度: ' + val + '%'
}
</script>

带标记

0°C
12°C
36°C
88°C
<template>
  <div>
    <b-slider v-model="value1" range :marks="marks"></b-slider>
  </div>
</template>

<script setup lang="ts">
import { ref, h } from 'vue'

const value1 = ref([15, 65])
const marks = {
  0: '0°C',
  12: '12°C',
  36: '36°C',
  88: {
    style: {
      color: '#ff0000'
    },
    label: h('strong', '88°C')
  }
}
</script>
<template>
  <div>
    <b-slider v-model="value1" range :marks="marks"></b-slider>
  </div>
</template>

<script setup lang="ts">
import { ref, h } from 'vue'

const value1 = ref([15, 65])
const marks = {
  0: '0°C',
  12: '12°C',
  36: '36°C',
  88: {
    style: {
      color: '#ff0000'
    },
    label: h('strong', '88°C')
  }
}
</script>

Props

参数说明类型可选值默认值
value / v-model绑定值number0
min最小值number0
max最大值number100
disabled是否禁用booleanfalse
step步长number1
show-input是否显示输入框,仅在非范围选择时有效booleanfalse
show-input-controls在显示输入框的情况下,是否显示输入框的控制按钮booleantrue
input-size输入框的尺寸stringlarge / default / small / minismall
show-stops是否显示间断点booleanfalse
show-tooltip是否显示 tooltipbooleantrue
format-tooltip格式化 tooltip messagefunction(value)
range是否为范围选择booleanfalse
vertical是否竖向模式booleanfalse
heightSlider 高度,竖向模式时必填string
label屏幕阅读器标签string
debounce输入时的去抖延迟,毫秒,仅在show-input等于true时有效number300
tooltip-classtooltip 的自定义类名string
marks标记, key 的类型必须为 number 且取值在闭区间 [min, max] 内,每个标记可以单独设置样式object

Events

事件名称说明回调参数
change值改变时触发(使用鼠标拖曳时,只在松开鼠标后触发)改变后的值
input数据改变时触发(使用鼠标拖曳时,活动过程实时触发)改变后的值