Skip to content

Swiper ​

Used to create carousels, supporting horizontal and vertical sliding, custom indicators, image and video resource display, and title rendering based on object data.

Please Note

Embedded videos are only supported on H5, WeChat Mini Program, and DingTalk Mini Program. Other platforms do not support this feature. Please understand before using.

Component Types ​

Dot Indicator ​

Basic carousel can display dot indicators through indicator configuration.

html
<wd-swiper :list="swiperList" autoplay v-model:current="current" :indicator="{ type: 'dots' }"></wd-swiper>
ts
import { ref } from 'vue'

const current = ref(0)

const swiperList = ref([
  'https://wot-ui.cn/assets/redpanda.jpg',
  'https://wot-ui.cn/assets/capybara.jpg',
  'https://wot-ui.cn/assets/panda.jpg',
  'https://wot-ui.cn/assets/moon.jpg',
  'https://wot-ui.cn/assets/meng.jpg'
])

Dots-Bar Indicator ​

html
<wd-swiper :list="swiperList" autoplay v-model:current="current" :indicator="{ type: 'dots-bar' }"></wd-swiper>

Fraction Indicator ​

html
<wd-swiper
  :list="swiperList"
  autoplay
  v-model:current="current"
  :indicator="{ type: 'fraction' }"
  indicator-position="bottom-right"
></wd-swiper>

Component Variants ​

Manual Switching ​

Turn off autoplay and enable showControls to manually switch carousel items through control buttons.

html
<wd-swiper
  :list="swiperList"
  :autoplay="false"
  v-model:current="current"
  :indicator="{ showControls: true }"
  :loop="false"
></wd-swiper>

Vertical Direction ​

html
<wd-swiper
  :list="swiperList"
  direction="vertical"
  indicator-position="right"
  autoplay
  v-model:current="current"
  :indicator="{ type: 'dots-bar' }"
></wd-swiper>

Specifying value-key and text-key ​

When list is an object array, you can specify the image address field and title field through value-key and text-key.

html
<wd-swiper value-key="url" text-key="title" :list="customSwiperList" autoplay v-model:current="current"></wd-swiper>
ts
import { ref } from 'vue'

const current = ref(0)

const customSwiperList = ref([
  { url: 'https://wot-ui.cn/assets/redpanda.jpg', title: 'Red Panda' },
  { url: 'https://wot-ui.cn/assets/capybara.jpg', title: 'Capybara' },
  { url: 'https://wot-ui.cn/assets/panda.jpg', title: 'Giant Panda' },
  { url: 'https://wot-ui.cn/assets/moon.jpg', title: 'Poetic China' }
])

Component Styles ​

Card Style ​

Set previous-margin and next-margin, combined with custom class names, to achieve card carousel style.

html
<view class="card-swiper">
  <wd-swiper
    autoplay
    v-model:current="current"
    :indicator="{ type: 'dots' }"
    :list="swiperList"
    previous-margin="24px"
    next-margin="24px"
    custom-indicator-class="custom-indicator-class"
    custom-image-class="custom-image"
    custom-next-image-class="custom-image-prev"
    custom-prev-image-class="custom-image-prev"
  ></wd-swiper>
</view>
scss
.card-swiper {
  --wot-swiper-radius: 0;
  --wot-swiper-item-padding: 0 24rpx;
  --wot-swiper-nav-dot-color: #e7e7e7;
  --wot-swiper-nav-dot-active-color: #4d80f0;
  padding-bottom: 24rpx;

  :deep(.custom-indicator-class) {
    bottom: -16px;
  }

  :deep(.custom-image) {
    border-radius: 12rpx;
  }

  :deep(.custom-image-prev) {
    height: 168px !important;
  }
}

Display 2 Items Simultaneously ​

Control the number of items displayed simultaneously through display-multiple-items.

html
<wd-swiper
  autoplay
  v-model:current="current"
  :display-multiple-items="2"
  :indicator="{ type: 'dots' }"
  :list="swiperList"
  previous-margin="24px"
  next-margin="24px"
></wd-swiper>

Custom Indicator ​

Fully customize indicator display through the indicator slot.

html
<wd-swiper :list="swiperList" direction="vertical" indicator-position="right" autoplay v-model:current="current">
  <template #indicator="{ current, total }">
    <view class="custom-indicator">{{ current + 1 }}/{{ total }}</view>
  </template>
</wd-swiper>
scss
.custom-indicator {
  position: absolute;
  right: 24rpx;
  bottom: 24rpx;
  padding: 0 12rpx;
  height: 48rpx;
  line-height: 48rpx;
  border-radius: 45%;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  font-size: 24rpx;
}

Special Styles ​

html
<wd-swiper :list="videoList" autoplay :indicator="{ type: 'fraction' }" indicator-position="top-right"></wd-swiper>
ts
import { ref } from 'vue'

const videoList = ref([
  'https://unpkg.com/wot-design-uni-assets@1.0.3/VID_115503.mp4',
  'https://unpkg.com/wot-design-uni-assets@1.0.3/VID_150752.mp4',
  'https://unpkg.com/wot-design-uni-assets@1.0.3/VID_155516.mp4',
  'https://wot-ui.cn/assets/moon.jpg'
])

Manual Video Playback ​

html
<wd-swiper
  :list="videoList"
  autoplay
  :autoplay-video="false"
  :indicator="{ type: 'fraction' }"
  indicator-position="top-right"
></wd-swiper>
html
<wd-swiper
  :list="videoList"
  autoplay
  stop-autoplay-when-video-play
  :autoplay-video="false"
  :indicator="{ type: 'fraction' }"
  indicator-position="top-right"
></wd-swiper>

Attribute Controlled Switching ​

html
<wd-swiper :loop="isLoop" :autoplay="false" :list="swiperList" v-model:current="current" />
<wd-gap />
<wd-cell-group>
  <wd-cell title="loop">
    <wd-switch v-model="isLoop" size="24px" />
  </wd-cell>
  <wd-cell title="current" :value="current.toString()" />
</wd-cell-group>
<view style="display: flex; justify-content: space-between">
  <wd-button @click="current--">prev</wd-button>
  <wd-button type="success" @click="current++">next</wd-button>
</view>

Slot Usage ​

Customize carousel item content through the default slot.

html
<wd-swiper :list="swiperList" autoplay v-model:current="current" :indicator="{ type: 'dots-bar' }">
  <template #default="{ item }">
    <image :src="item as string" mode="aspectFill" style="width: 100%; height: 100%" />
  </template>
</wd-swiper>

Attributes ​

ParameterDescriptionTypeDefault Value
autoplayWhether to auto-playbooleantrue
v-model:currentCurrent carousel item indexnumber0
directionCarousel direction, optional values are horizontal, verticalDirectionTypehorizontal
display-multiple-itemsNumber of items displayed simultaneouslynumber1
durationSlide animation duration, unit is msnumber300
easing-functionTransition easing animation type, optional values are default, linear, easeInCubic, easeOutCubic, easeInOutCubicEasingTypedefault
heightCarousel heightstring | number192
intervalAuto-play interval time, unit is msnumber5000
listCarousel data list, supports string array or object arraystring[] | SwiperItem[][]
loopWhether to loop playbackbooleantrue
video-loopWhether video loops playbackbooleantrue
mutedWhether video plays mutedbooleantrue
next-marginRear marginstring | number0
indicator-positionIndicator position, optional values are left, top-left, top, top-right, bottom-left, bottom, bottom-right, rightIndicatorPositionTypebottom
previous-marginFront marginstring | number0
radiusCarousel border radiusstring | number-
snap-to-edgeWhether to apply margin to first and last elementsbooleanfalse
indicatorIndicator configuration, pass false to hide indicatorboolean | Partial<SwiperIndicatorProps>true
image-modeImage cropping mode, refer to uni-app Image component modeImageModeaspectFill
show-menu-by-longpressWhether to enable long-press image to show QR code recognition menubooleanfalse
value-keyImage address field name in option objectsstringvalue
text-keyTitle field name in option objectsstringtext
autoplay-videoWhether video auto-playsbooleantrue
stop-previous-videoWhether to stop previous video playback when switching carousel itemsbooleantrue
stop-autoplay-when-video-playWhether to stop auto-play when video is playingbooleanfalse
adjust-heightAutomatically adjust container height based on item height, optional values are first, current, highest, none, only supported on Alipay Mini ProgramAdjustHeightTypehighest
adjust-vertical-heightForce adjust-height to take effect when vertical is true, only supported on Alipay Mini Programbooleanfalse
custom-indicator-classCustom indicator class namestring''
custom-image-classCustom image class namestring''
custom-prev-image-classCustom previous image class namestring''
custom-next-image-classCustom next image class namestring''
custom-item-classCustom carousel item class namestring''
custom-prev-classCustom previous carousel item class namestring''
custom-next-classCustom next carousel item class namestring''
custom-text-classCustom title class namestring''
custom-text-styleCustom title stylestring''
custom-classRoot node custom style classstring''
custom-styleRoot node custom stylestring''

Events ​

Event NameDescriptionParameters
clickTriggered when clicking carousel item{ index: number; item: SwiperItem | string }
changeTriggered when carousel switches{ current: number; source: string }
animationfinishTriggered when carousel animation ends{ current: number; source: string }
update:currentTriggered when current carousel item updatesnumber

Slots ​

NameDescription
defaultCustom carousel item content, parameters are { item, index }
indicatorCustom indicator content, parameters are { current, total }

Type Definitions ​

DirectionType ​

Carousel direction, optional values are horizontal, vertical.

EasingType ​

Transition easing animation type, optional values are default, linear, easeInCubic, easeOutCubic, easeInOutCubic.

IndicatorPositionType ​

Indicator position, optional values are left, top-left, top, top-right, bottom-left, bottom, bottom-right, right.

AdjustHeightType ​

Auto height strategy, optional values are first, current, highest, none.

SwiperIndicatorType ​

Indicator type, optional values are dots, dots-bar, fraction.

SwiperItem ​

Carousel item object configuration, supports extended fields.

ParameterDescriptionTypeDefault Value
valueImage or video addressstring-
posterVideo cover addressstring-
typeResource type, optional values are image, videoSwiperItemType-

SwiperIndicator Attributes ​

ParameterDescriptionTypeDefault Value
currentCurrent carousel item indexnumber0
directionCarousel direction, optional values are horizontal, verticalDirectionTypehorizontal
min-show-numDo not show navigator when less than this numbernumber2
indicator-positionIndicator position, optional values are left, top-left, top, top-right, bottom-left, bottom, bottom-right, rightIndicatorPositionTypebottom
show-controlsWhether to show control buttons on both sidesbooleanfalse
totalTotal number of carousel itemsnumber0
typeIndicator type, optional values are dots, dots-bar, fractionSwiperIndicatorTypedots

主题定制 ​

CSS 变量 ​

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置。

名称默认值描述
--wot-swiper-border-radius$radius-zero轮播容器圆角
--wot-swiper-item-padding$padding-zero轮播项内边距
--wot-swiper-item-text-color$text-white轮播文案颜色
--wot-swiper-item-text-font-size$typography-body-size-extra-large轮播文案字号
--wot-swiper-item-text-spacing$spacing-loose轮播文案定位间距

Source Code ​

Documentation
• Component

Released under the MIT License.

Released under the MIT License.