Range组件

介绍

滑动输入条,用于在给定的范围内选择一个值。

安装

  1. import { createApp } from 'vue';
  2. import { Range } from '@nutui/nutui';
  3. const app = createApp();
  4. app.use(Range);

代码演示

基础用法

  1. <nut-range v-model="value" @change="onChange"></nut-range>
  1. import { ref } from 'vue';
  2. import { Toast } from '@nutui/nutui';
  3. export default {
  4. setup() {
  5. const value = ref(40);
  6. const onChange = (value) => Toast.text('当前值:' + value);
  7. return {
  8. value,
  9. onChange,
  10. };
  11. },
  12. };

双滑块

  1. <nut-range range v-model="value" @change="onChange"></nut-range>
  1. import { ref } from 'vue';
  2. import { Toast } from '@nutui/nutui';
  3. export default {
  4. setup() {
  5. const value = ref([20, 80]);
  6. const onChange = (value) => Toast.text('当前值:' + value);
  7. return {
  8. value,
  9. onChange,
  10. };
  11. },
  12. };

指定范围

  1. <nut-range v-model="value" :max="10" :min="-10" @change="onChange"></nut-range>

设置步长

  1. <nut-range v-model="value" :step="5" @change="onChange"></nut-range>

隐藏范围

  1. <nut-range v-model="value" hidden-range @change="onChange"></nut-range>

隐藏标签

  1. <nut-range v-model="value" hidden-tag @change="onChange"></nut-range>

禁用

  1. <nut-range v-model="value" disabled @change="onChange"></nut-range>

自定义样式

  1. <nut-range
  2. v-model="value"
  3. inactive-color="rgba(163,184,255,1)"
  4. button-color="rgba(52,96,250,1)"
  5. active-color="linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%"
  6. @change="onChange">
  7. </nut-range>

自定义按钮

  1. <nut-range v-model="value" @change="onChange">
  2. <template #button>
  3. <div class="custom-button"></div>
  4. </template>
  5. </nut-range>
  6. <style>
  7. .custom-button {
  8. width: 26px;
  9. color: #fff;
  10. font-size: 10px;
  11. line-height: 18px;
  12. text-align: center;
  13. background-color: #ee0a24;
  14. border-radius: 100px;
  15. }
  16. </style>

API

Props

参数说明类型默认值
v-model当前进度百分比Number、Number[]0
range是否开启双滑块模式Booleanfalse
max最大值Number、String100
min最小值Number、String0
step步长Number、String1
disabled是否禁用滑块Booleanfalse
hidden-range是否隐藏范围值Booleanfalse
hidden-tag是否隐藏标签Booleanfalse
active-color进度条激活态颜色Stringrgba(250, 44, 25, 1)
inactive-color进度条非激活态颜色Stringrgba(255, 163, 154, 1)
button-color按钮颜色Stringrgba(250, 44, 25, 1)

Events

事件名说明回调参数
change进度变化且结束拖动后触发value: 当前进度
drag-start开始拖动时触发-
drag-end结束拖动时触发-

Slots

名称说明
button自定义滑动按钮

Range  区间选择器 - 图1