Skip to content
# t-slider

Slider 滑块

t-slider 组件介绍 ​

t-slider 是一个基于 Canvas 绘制的滑块组件,支持水平/垂直方向、单滑块/多滑块、显示数值/百分比等丰富功能。适用于音量调节、亮度调节、价格区间选择等场景。

t-slider 平台兼容 ​

HarmonyH5AndroidiOS小程序UTS
✅✅✅✅✅✅

t-slider 基础用法 ​

基础用法参考 demo/slider/slider.uvue,通过 v-model 双向绑定滑块值。

vue
<template>
	<view class="p-15">
		<tui-theme-switch></tui-theme-switch>
		<t-card title='SliderPlus 滑块升级版'
				sub-title="canvas绘制丝滑不卡,支持显示百分比或者显示值,支持多滑块,滑块数据取决于绑定value值数组的长度"
				class="mb-15"></t-card>
		<t-section class="mb-15"
				   title="显示值"></t-section>
		<t-slider class="r-10 h-130 mb-15"
				  direction="horizontal"
				  :min="0"
				  :max="500"
				  type="primary"
				  blockSize="30"
				  :disabled="false"
				  :showValue="true"
				  trackSize="10"
				  v-model="values"
				  showMode="after" />
		<t-section class="mb-15"
				   title="显示百分比"></t-section>
		<t-slider class="r-10 h-130 mb-15"
				  direction="horizontal"
				  type="primary"
				  blockSize="25"
				  :disabled="false"
				  trackSize="5"
				  :modelValue="[0]" />
		<t-section class="mb-15"
				   title="防止文本超出边界"></t-section>
		<t-slider class="r-10 h-130 mb-15"
				  :min="999999999"
				  :max="99999999999"
				  direction="horizontal"
				  type="primary"
				  :showValue="true"
				  blockSize="25"
				  :disabled="false"
				  trackSize="5"
				  :modelValue="[999999999, 99999999999]" />
		<t-row class="mb-15">
			<t-slider class="r-10 h-300 w-130 mr-15"
					  :min="0"
					  :max="500"
					  :modelValue="[0, 105, 250]"
					  direction="vertical"
					  type="error"
					  showMode="after"
					  blockSize="25"
					  trackSize="10" />
			<t-slider class="r-10 h-300 w-130"
					  :min="0"
					  :max="500"
					  :modelValue="[0, 105, 250]"
					  direction="vertical"
					  type="success"
					  blockSize="25"
					  trackSize="10" />
		</t-row>
	</view>
</template>

<script setup>
	const values = ref([0, 105, 500])
</script>

t-slider Props ​

属性名说明类型默认值
path点击组件后跳转的页面路径;为空时仅响应事件string''
hover是否启用点击效果booleanfalse
type组件主题类型,可选 info、primary、error、warning、successstring'primary'
disabled是否禁用booleanfalse
effect组件显示主题,可选 normal、dark、light、plainstring'normal'
size组件尺寸,可选 large、medium、small、ministring''
direction滑块方向,可选 horizontal、verticalstring'horizontal'
min最小值number0
max最大值number100
modelValue双向绑定的值,数组格式支持多滑块number[][]
activeColor已选择部分的颜色string''(使用主题色)
inactiveColor未选择部分的颜色string'#f2f2f2'
blockSize滑块按钮的大小string'50'
fontSize数值显示字体大小string'28rpx'
showValue是否显示具体数值booleanfalse
showValuePosition是否显示百分比booleantrue
decimalPlaces保留的小数位数number0
trackSize滑块轨道尺寸string'5'
showMode数值显示位置,可选 before(滑块前)、after(滑块后)string'before'

t-slider Events ​

事件名说明回调参数
update:modelValue值更新时触发number[]
change值发生变化时触发number[]