# Slider 滑块

### 引入

在`index.config.js中引入组件

```json
"usingComponents": {
  "van-slider": "@vant/weapp/slider/index"
}
```

## 代码演示

### 基本用法

```html
<van-slider value="50"  step={1} min={1} max={100} onChange={(e)=>this.onChange(e) />
```

```js

 onChange(event) {
    wx.showToast({
      icon: 'none',
      title: `当前值：${event.detail}`
    });
  }

```

### 指定选择范围

```html
<van-slider min="-50" max="50" step={1} value="50" />
```

### 禁用

```html
<van-slider value="50" step={1} min={1} max={100} disabled />
```

### 指定步长

```html
<van-slider value="50" step="10" min={1} max={100} />
```

### 自定义样式

```html
<van-slider value="50" step={1} min={1} max={100} barHeight="4px" activeColor="#ee0a24" />
```

### 自定义按钮

```html
  <van-slider
            value={ this.state.currentValue }
            step={1}
            min={1}
            max={100}
            customClass="slider"
            useButtonSlot={true}
            activeColor="#ee0a24"
            onDrag={(e)=>this.onDrag(e)}
          >
            <view className="custom-button" slot="button">
              {this.state.currentValue }
            </view>
          </van-slider>
```

```js

  state= {
    currentValue: 50,
  }
  onDrag(event) {
    this.setState({
      currentValue: event.detail.value,
    });
  }

```

## API
### 注:属性应用在组件上需要统一使用驼峰式命名，如custom-class应变为
```html
<van-button type="primary" customClass='myClass' size="large">大号按钮</van-button>
```
### 注:事件应用在组件上需要统一使用驼峰式命名，如bind:click/bind:search/bind:before-enter应变为
```html
<van-button type="primary" onClick={()=>this.onClick()}>大号按钮</van-button>
<van-search type="primary" onSearch={()=>this.onSearch()}>大号按钮</van-search>
<van-transition type="primary" onBeforeEnter={()=>this.onBeforeEnter()}>大号按钮</van-transition>
```
### Props

| 参数 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| value | 当前进度百分比，取值范围为 0-100 | _number_ | `0` | - |
| disabled | 是否禁用滑块 | _boolean_ | `false` | - |
| max | 最大值 | _number_ | `100` | - |
| min | 最小值 | _number_ | `0` | - |
| step | 步长 | _number_ | `1` | - |
| bar-height | 进度条高度，默认单位为 `px` | _string \| number_ | `2px` | - |
| active-color | 进度条激活态颜色 | _string_ | `#1989fa` | - |
| inactive-color | 进度条默认颜色 | _string_ | `#e5e5e5` | - |

### Events

| 事件名          | 说明             | 参数                         |
| --------------- | ---------------- | ---------------------------- |
| bind:drag       | 拖动进度条时触发 | event.detail.value: 当前进度 |
| bind:change     | 进度值改变后触发 | event.detail: 当前进度       |
| bind:drag-start | 开始拖动时触发   | -                            |
| bind:drag-end   | 结束拖动时触发   | -                            |

### 外部样式类

| 类名         | 说明         |
| ------------ | ------------ |
| custom-class | 根节点样式类 |
