# Swipe
### Install
``` javascript
import { Swipe, SwipeItem } from 'vant';
Vue.use(Swipe).use(SwipeItem);
```
## Usage
### Basic Usage
Use `autoplay` prop to set autoplay interval
```html
1
2
3
4
```
### Image Lazyload
Use [Lazyload](#/en-US/lazyload) component to lazyload image
```html
```
```javascript
export default {
data() {
return {
images: [
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
]
}
}
}
```
### change event
```html
1
2
3
4
```
```js
export default {
methods: {
onChange(index) {
Toast('Current Swipe index:' + index);
}
}
}
```
### Vertical Scrolling
```html
1
2
3
4
```
### Set Swiper Item Size
```html
1
2
3
4
```
### Custom Indicator
```html
1
2
3
4
{{ current + 1 }}/4
```
```js
export default {
data() {
return {
current: 0
}
},
methods: {
onChange(index) {
this.current = index;
}
}
}
```
## API
### Swipe Props
| Attribute | Description | Type | Default |
|------|------|------|------|
| autoplay | Autoplay interval (ms) | `Number` | - |
| duration | Animation duration (ms) | `Number` | `500` |
| loop | Whether to enable loop | `Boolean` | `true` |
| vertical | Vertical Scrolling | `Boolean` | `false` |
| touchable | Whether touchable | `Boolean` | `true` |
| show-indicators | Whether to show indicators | `Boolean` | `true` |
| indicator-color | Indicator color | `String` | `#1989fa` |
| initial-swipe | Index of initial swipe, start from 0 | `Number` | `0` |
| width | Set Swiper Item Width | `Number` | `0` |
| height | Set Swiper Item Height | `Number` | `0` |
### Swipe Events
| Event | Description | Arguments |
|------|------|------|
| change | Triggered when current swipe change | index: index of current swipe |
### Swipe Methods
Use ref to get swipe instance and call instance methods
| Name | Attribute | Return value | Description |
|------|------|------|------|
| swipeTo | index: target index | void | Swipe to target index |
### Swipe Slots
| Name | Description |
|------|------|
| default | Content |
| indicator | Custom indicator |