Skip to content
On this page

Slider 滑块选择器

注:

  • 支持表单,具体可参考 Form
vue
<template>
  <ta-group title="基础用法">
    <ta-cell class="exp-slider-box" :label="'value: ' + value">
      <ta-slider v-model="value" />
    </ta-cell>
  </ta-group>
  <ta-group title="显示数值 showValue=true">
    <ta-cell class="exp-slider-box" :label="'value: ' + value2">
      <ta-slider show-value v-model="value2" />
    </ta-cell>
  </ta-group>
  <ta-group title="自定义颜色 color=#ff7875">
    <ta-cell class="exp-slider-box" :label="'value: ' + value3">
      <ta-slider color="#ff7875" v-model="value3" show-value />
    </ta-cell>
  </ta-group>
  <ta-group title="设置步进(step=5)">
    <ta-cell class="exp-slider-box" :label="'value: ' + value4">
      <ta-slider show-value v-model="value4" step="5" />
    </ta-cell>
  </ta-group>
  <ta-group title="限制范围 min=40 & max=140">
    <ta-cell class="exp-slider-box" :label="'value: ' + value5">
      <ta-slider show-value :min="min" :max="max" v-model="value5" />
    </ta-cell>
  </ta-group>
  <ta-group title="禁用">
    <ta-cell class="exp-slider-box" :label="'value: ' + value6">
      <ta-slider disabled v-model="value6" />
    </ta-cell>
  </ta-group>
  <ta-group title="事件监听">
    <ta-cell class="exp-slider-box" label="input"
      ><ta-slider v-model="value7" @input="onInput" />
    </ta-cell>
    <ta-cell class="exp-slider-box" label="change"
      ><ta-slider v-model="value8" @change="onChange" />
    </ta-cell>
  </ta-group>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { showToast } from '@/index'

export default defineComponent({
  name: 'ExpSlider',
  data() {
    return {
      min: 40,
      max: 140,

      value: undefined,
      value2: 10,
      value3: 20,
      value4: 30,
      value5: 40,
      value6: 50,
      value7: 60,
      value8: 70
    }
  },
  methods: {
    onInput(value: number) {
      showToast(`Input value: ${value}`)
    },
    onChange(value: number) {
      showToast(`Change value: ${value}`)
    }
  }
})
</script>

Import

js
import { TaSlider } from 'tantalum-ui-mobile'

具体的引入方式可以参考引入组件

Props

属性类型默认值必填说明
v-modelnumber
namestring标识
minnumber | string0最小值
maxnumber | string100最大值
stepnumber | string1步长,取值必须大于 0,并且可被(max - min)整除
disabledbooleanfalse是否禁用
show-valuebooleanfalse是否显示当前 value
colorstring设置主色

Events

事件描述回调函数参数
input拖动过程中触发的事件value: number
change完成一次拖动后触发的事件value: number