# Swipe
### Intro
Used to loop a group of pictures or content.
### Install
Register component globally via `app.use`, refer to [Component Registration](#/en-US/advanced-usage#zu-jian-zhu-ce) for more registration ways.
```js
import { createApp } from 'vue';
import { Swipe, SwipeItem } from 'vant';
const app = createApp();
app.use(Swipe);
app.use(SwipeItem);
```
## Usage
### Basic Usage
Use `autoplay` prop to set autoplay interval.
```html
1
2
3
4
```
### Lazy Render
Use `lazy-render` prop to enable lazy rendering.
```html
```
```js
export default {
setup() {
const images = [
'https://img.yzcdn.cn/vant/apple-1.jpg',
'https://img.yzcdn.cn/vant/apple-2.jpg',
];
return { images };
},
};
```
### Change Event
```html
1
2
3
4
```
```js
import { Toast } from 'vant';
export default {
setup() {
const onChange = (index) => Toast('Current Swipe index:' + index);
return { onChange };
},
};
```
### Vertical Scrolling
```html
1
2
3
4
```
### Set SwipeItem Size
```html
1
2
3
4
```
> It's not supported to set SwipeItem size in the loop mode.
### Custom Indicator
```html
1
2
3
4
{{ active + 1 }}/4
```
## API
### Swipe Props
| Attribute | Description | Type | Default |
| --- | --- | --- | --- |
| autoplay | Autoplay interval (ms) | _number \| string_ | - |
| duration | Animation duration (ms) | _number \| string_ | `500` |
| initial-swipe | Index of initial swipe, start from 0 | _number \| string_ | `0` |
| width | Set Swiper Item Width | _number \| string_ | `0` |
| height | Set Swiper Item Height | _number \| string_ | `0` |
| loop | Whether to enable loop | _boolean_ | `true` |
| show-indicators | Whether to show indicators | _boolean_ | `true` |
| vertical | Whether to be vertical Scrolling | _boolean_ | `false` |
| touchable | Whether to allow swipe by touch gesture | _boolean_ | `true` |
| stop-propagation | Whether to stop touchmove event propagation | _boolean_ | `false` |
| lazy-render | Whether to enable lazy render | _boolean_ | `false` |
| indicator-color | Indicator color | _string_ | `#1989fa` |
### Swipe Events
| Event | Description | Arguments |
| ------ | ---------------------------------- | ----------------------------- |
| change | Emitted when current swipe changed | index: index of current swipe |
### SwipeItem Events
| Event | Description | Arguments |
| ----- | --------------------------------- | ------------------- |
| click | Emitted when component is clicked | _event: MouseEvent_ |
### Swipe Methods
Use [ref](https://v3.vuejs.org/guide/component-template-refs.html) to get Swipe instance and call instance methods..
| Name | Description | Attribute | Return value |
| --- | --- | --- | --- |
| prev | Swipe to prev item | - | - |
| next | Swipe to next item | - | - |
| swipeTo | Swipe to target index | _index: number, options: SwipeToOptions_ | - |
| resize | Resize Swipe when container element resized or visibility changed | - | - |
### Types
Get the type definition of the Swipe instance through `SwipeInstance`.
```ts
import { ref } from 'vue';
import type { SwipeInstance } from 'vant';
const swipeRef = ref();
swipeRef.value?.next();
```
### SwipeToOptions
| Name | Description | Type |
| --------- | ------------------------- | --------- |
| immediate | Whether to skip animation | _boolean_ |
### Swipe Slots
| Name | Description | SlotProps |
| ------------------- | ---------------- | -------------------- |
| default | Content | - |
| indicator `v3.0.16` | Custom indicator | _{ active: number }_ |
### CSS Variables
The component provides the following CSS variables, which can be used to customize styles. Please refer to [ConfigProvider component](#/en-US/config-provider).
| Name | Default Value | Description |
| --- | --- | --- |
| --van-swipe-indicator-size | _6px_ | - |
| --van-swipe-indicator-margin | _var(--van-padding-sm)_ | - |
| --van-swipe-indicator-active-opacity | _1_ | - |
| --van-swipe-indicator-inactive-opacity | _0.3_ | - |
| --van-swipe-indicator-active-background-color | _var(--van-primary-color)_ | - |
| --van-swipe-indicator-inactive-background-color | _var(--van-border-color)_ | - |