vant/src/slider/README.zh-CN.md
lmx-Hexagram f36961fe29
docs: change slot to # (#5858)
* docs(SwipeCell): change "slot" to "v-slot"

* docs(SwipeCell): change `v-slot` to`#`

* docs(cell): change `slot` to `#`

* docs(checkbox): change `slot` to `v-slot`

* docs(field): change `slot` to `v-slot`

* docs(checkbox): remove wrong comment

* docs(radio): change `slot` to `#`

* docs(search): change `slot` to `#`

* docs(slider): change `slot` to `#`

* docs(switch): change `slot` to `#`

* docs(PullRefresh): change `slot` to `#`

* docs(collapse): change `slot` to `#`

* docs(panel): change `slot` to `#`

* docs(swipe): change `slot` to `#`

* docs(navbar): change `slot` to `#`

* docs(tab): change `slot` to `#`

* docs(tabber): change `slot` to `#`

* docs(TreeSelect): change `slot` to `#`

* docs(card): change `slot` to `#`

* docs(submitBar): change `slot` to `#`

* docs(sku): change `slot` to `#` unsure

* docs(cell): delete waste blank line

* docs(panel): fix indentation

* docs(PullRefresh): change "count" to "Refresh Count"

* docs(radio): delete waste blank line

* docs(search): move props above the event

* docs(submitBar): delete waste `<span>`

* docs(swipCell): delete waste blank line

* docs(tabbar): merge `<img>` into one line
2020-03-20 14:12:00 +08:00

2.3 KiB

Slider 滑块

引入

import Vue from 'vue';
import { Slider } from 'vant';

Vue.use(Slider);

代码演示

基本用法

<van-slider v-model="value" @change="onChange" />
import { Toast } from 'vant';

export default {
  data() {
    return {
      value: 50
    };
  },
  methods: {
    onChange(value) {
      Toast('当前值:' + value);
    }
  }
};

指定选择范围

<van-slider v-model="value" :min="-50" :max="50" />

禁用

<van-slider v-model="value" disabled />

指定步长

<van-slider v-model="value" :step="10" />

自定义样式

<van-slider
  v-model="value"
  bar-height="4px"
  active-color="#ee0a24"
/>

自定义按钮

<van-slider v-model="value" active-color="#ee0a24">
  <template #button>
    <div class="custom-button">
      {{ value }}
    </div>
  </template>
</van-slider>

<style>
.custom-button {
  width: 26px;
  color: #fff;
  font-size: 10px;
  line-height: 18px;
  text-align: center;
  background-color: #ee0a24;
  border-radius: 100px;
}
</style>

垂直方向

Slider 垂直展示时,高度为 100% 父元素高度

<div :style="{ height: '100px' }">
  <van-slider v-model="value" vertical />
</div>

API

Props

参数 说明 类型 默认值
value 当前进度百分比 number 0
max 最大值 number | string 100
min 最小值 number | string 0
step 步长 number | string 1
bar-height 进度条高度,默认单位为px number | string 2px
button-size v2.4.5 滑块按钮大小,默认单位为px number | string 24px
active-color 进度条激活态颜色 string #1989fa
inactive-color 进度条非激活态颜色 string #e5e5e5
disabled 是否禁用滑块 boolean false
vertical 是否垂直展示 boolean false

Events

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

Slots

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