Slider 滑动输入条

何时使用

当用户需要在数值区间内进行选择时使用。

基本用法

020

<template>
  <d-slider :min="minValue" :max="maxValue" v-model="inputValue"></d-slider>
  <div class="flex-space-between">
    <span>{{ minValue }}</span>
    <span>{{ maxValue }}</span>
  </div>
</template>

<script>
import { defineComponent, ref } from 'vue';

export default defineComponent({
  setup() {
    const inputValue = ref(12);
    const minValue = ref(0);
    const maxValue = ref(20);
    return {
      inputValue,
      maxValue,
      minValue,
    };
  },
});
</script>

<style scoped>
.flex-space-between {
  display: flex;
  justify-content: space-between;
}
</style>

可设置 Step 的滑动组件

020

<template>
  <d-slider :min="minValue" :max="maxValue" v-model="inputValue" :step="step"></d-slider>
  <div class="flex-space-between">
    <span>{{ minValue }}</span>
    <span>{{ maxValue }}</span>
  </div>
</template>
<script>
import { defineComponent, ref } from 'vue';

export default defineComponent({
  setup() {
    const inputValue = ref(8);
    const minValue = ref(0);
    const maxValue = ref(20);
    const step = ref(4);
    return {
      inputValue,
      maxValue,
      minValue,
      step,
    };
  },
});
</script>

<style scoped>
.flex-space-between {
  display: flex;
  justify-content: space-between;
}
</style>

带有输入框的滑动组件

020

<template>
  <div class="flex-space-between">
    <div class="slider-wrapper">
      <d-slider :min="minValue" :max="maxValue" v-model="inputValue"></d-slider>
      <div class="flex-space-between">
        <span>{{ minValue }}</span>
        <span>{{ maxValue }}</span>
      </div>
    </div>
    <div class="snapshot-value">
      <d-input-number  v-model="inputValue" :min="0" :max="20"></d-input-number>
    </div>
  </div>

</template>
<script>
import { defineComponent, ref } from 'vue';

export default defineComponent({
  setup() {
    const inputValue = ref(10);
    const minValue = ref(0);
    const maxValue = ref(20);
    return {
      inputValue,
      maxValue,
      minValue,
    };
  },
});
</script>

<style scoped>
.flex-space-between {
  display: flex;
  justify-content: space-between;
}

.slider-wrapper {
  width: calc(100% - 100px);
}

.snapshot-value {
  width: 80px;
  margin-left: 20px;
}
</style>

禁止输入态

250

<template>
  <d-slider :min="minValue" :max="maxValue" disabled v-model="disabledValue"></d-slider>
  <div class="flex-space-between">
    <span>{{ minValue }}</span>
    <span>{{ maxValue }}</span>
  </div>
</template>
<script>
import { defineComponent, ref } from 'vue';

export default defineComponent({
  setup() {
    const disabledValue = ref(5);
    const maxValue = ref(50);
    const minValue = ref(2);
    return {
      disabledValue,
      maxValue,
      minValue,
    };
  },
});
</script>

<style scoped>
.flex-space-between {
  display: flex;
  justify-content: space-between;
}
</style>

定制 Popover 显示内容

通过 tipsRenderer 参数传入定制 Popover 内的显示内容。

250

250

<template>
  <div>
    <d-slider :min="minValue" :max="maxValue" v-model="inputValue" :tips-renderer="tipsRender"></d-slider>
    <div class="flex-space-between">
      <span>{{ minValue }}</span>
      <span>{{ maxValue }}</span>
    </div>

    <br style="margin-bottom: 20px" />

    <d-slider :min="minValue" :max="maxValue" v-model="inputValue" :tips-renderer="null"></d-slider>
    <div class="flex-space-between">
      <span>{{ minValue }}</span>
      <span>{{ maxValue }}</span>
    </div>
  </div>
</template>

<script>
import { defineComponent, ref } from 'vue';

export default defineComponent({
  setup() {
    const inputValue = ref(5);
    const maxValue = ref(50);
    const minValue = ref(2);
    const tipsRender = (val) => `${val} apples`;
    return {
      inputValue,
      maxValue,
      minValue,
      tipsRender,
    };
  },
});
</script>

<style scoped>
.flex-space-between {
  display: flex;
  justify-content: space-between;
}
</style>

Slider 参数

参数类型默认说明跳转
maxnumber100可选,滑动输入条的最大值基本用法
minnumber0可选,滑动输入条的最小值基本用法
stepnumber1可选,滑动输入条的步长,取值必须大于等于 1,且必须可被(max-min)整除可设置 Step 的滑动组件
disabledbooleanfalse可选,值为 true 时禁止用户输入禁止输入态
tips-rendererstring(val) => String(val)可选,渲染 Popover 内容的函数,传入 null 时不显示 Popover定制 popover 显示内容
Contributors