Skip to content

Swiper

Used to create carousels, supporting horizontal and vertical sliding, customizable styles and indicator positions, supports video and image resource carousels, and allows setting carousel titles and custom title styles.

Please Note

Embedded video is only supported in h5, WeChat Mini Program, and DingTalk Mini Program. Other platforms do not support it, please be aware before using.

Basic Usage

Control whether the carousel automatically plays through the autoplay property, initialize the displayed slide with the v-model:current property, handle click events by listening to the slide's click, and trigger the change event after each page carousel ends.

html
<wd-swiper :list="swiperList" autoplay v-model:current="current" @click="handleClick" @change="onChange"></wd-swiper>
ts
const current = ref<number>(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'
])
function handleClick(e) {
  console.log(e)
}
function onChange(e) {
  console.log(e)
}

Dots Bar Indicator

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

Fraction Indicator

html
<wd-swiper
  :list="swiperList"
  autoplay
  v-model:current="current"
  :indicator="{ type: 'fraction' }"
  indicatorPosition="bottom-right"
  @click="handleClick"
  @change="onChange"
></wd-swiper>

Video Carousel1.3.13

Please Note

Embedded video is only supported in h5, WeChat Mini Program, and DingTalk Mini Program. Other platforms do not support it, please be aware before using.

html
<wd-swiper :list="videoList" autoplay :indicator="false" indicator-position="bottom-right"></wd-swiper>
ts
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 :autoplayVideo="false" :indicator="{ type: 'fraction' }" indicator-position="top-right"></wd-swiper>
ts
const videoList = ref([
  'https://unpkg.com/wot-design-uni-assets/VID_115503.mp4',
  'https://unpkg.com/wot-design-uni-assets/VID_150752.mp4',
  'https://unpkg.com/wot-design-uni-assets/VID_155516.mp4'
])
html
<wd-swiper
  :list="videoList"
  autoplay
  stopAutoplayWhenVideoPlay
  :autoplayVideo="false"
  :indicator="{ type: 'fraction' }"
  indicator-position="top-right"
></wd-swiper>
ts
const videoList = ref([
  'https://unpkg.com/wot-design-uni-assets/VID_115503.mp4',
  'https://unpkg.com/wot-design-uni-assets/VID_150752.mp4',
  'https://unpkg.com/wot-design-uni-assets/VID_155516.mp4'
])

Manual Switching

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

Card Style

Set previousMargin and nextMargin to achieve card carousel style.

html
<view class="card-swiper">
  <wd-swiper
    autoplay
    v-model:current="current"
    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"
    :indicator="{ type: 'dots' }"
    :list="swiperList"
    previousMargin="24px"
    nextMargin="24px"
  ></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 Multiple Items

Set the display-multiple-items property to control the number of slides displayed simultaneously.

html
<view class="card-swiper">
  <wd-swiper
    autoplay
    v-model:current="current"
    :display-multiple-items="2"
    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"
    :indicator="{ type: 'dots' }"
    :list="swiperList"
    previousMargin="24px"
    nextMargin="24px"
  ></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;
  }
}

Vertical Direction

Set direction to vertical to arrange slides vertically.

html
<wd-swiper
  :list="swiperList"
  direction="vertical"
  indicatorPosition="right"
  autoplay
  v-model:current="current"
  :indicator="{ type: 'dots-bar' }"
  @click="handleClick"
  @change="onChange"
></wd-swiper>

Custom Indicator

Use the indicator slot to customize the indicator style.

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

Specify valueKey and textKey

Use value-key to specify the image address field in each object of the list, default is value.

Use text-key to specify the title field in each object of the list, default is text.

html
<wd-swiper
  value-key="url"
  text-key="title"
  :list="customSwiperList"
  autoplay
  v-model:current="current"
  @click="handleClick"
  @change="onChange"
></wd-swiper>
ts
const current = ref<number>(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!' }
])

Property Control 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>
javascript
const current = ref<number>(0)
const isLoop = ref(false)

Slot Usage

Use the default slot to customize the content of carousel items.

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

Attributes

ParameterDescriptionTypeOptional ValuesDefault ValueMinimum Version
autoplayWhether to enable auto-playboolean-true0.1.22
v-model:currentControl which carousel item is currently displayed (index)number-00.1.22
directionCarousel sliding directionDirectionTypehorizontal, verticalhorizontal0.1.22
displayMultipleItemsNumber of slides displayed simultaneouslynumber-10.1.22
durationSlide animation durationnumber-3000.1.22
easingFunctionSwitching easing animation type (WeChat Mini Program, Kuaishou Mini Program, JD Mini Program)EasingType-default0.1.22
heightHeight of the carouselstring / number-1920.1.22
intervalCarousel interval timenumber-50000.1.22
listImage liststring[] / SwiperList[]--0.1.22
loopWhether to enable loop playbackboolean-true0.1.22
nextMarginNext marginstring / number-00.1.22
indicatorPositionIndicator display positionIndicatorPositionTypeleft, top-left, top, top-right, bottom-left, bottom, bottom-right, rightbottom0.1.22
previousMarginPrevious marginstring / number-00.1.22
snapToEdgeWhether margins should apply to first and last elementsboolean-false0.1.22
indicatorComplete indicator configurationSwiperIndicatorProps / boolean-true0.1.22
imageModeImage cropping and scaling modestringRefer to official documentation modeaspectFill0.1.55
autoplayVideoWhether videos auto-play, default is auto-playboolean-true1.3.13
stopPreviousVideoWhether to stop previous video playback when switching carousel items, default stops previous video when switchingboolean-true1.3.13
stopAutoplayWhenVideoPlayWhether to stop auto-carousel when video is playingboolean-false1.3.13
customStyleExternal custom stylestring-''0.1.22
value-keyKey corresponding to value in option objectstring-value1.3.7
text-keyKey corresponding to title text in option objectstring-text1.3.13
adjust-heightAutomatically use specified slide height as entire container height. When vertical is true, default is not adjusted, only supported by Alipay Mini Program.string'first' / 'current' / 'highest' / 'none'highest1.3.13
adjust-vertical-heightForce adjust-height to take effect when vertical is true. Only supported by Alipay Mini Program.boolean-false1.3.13
mutedWhether video plays mutedboolean-true1.6.0
videoLoopWhether video loopsboolean-true1.6.0

DirectionType

Carousel sliding direction, optional values are 'horizontal' and 'vertical'.

EasingType

Switching easing animation type, optional values are 'default', 'linear', 'easeInCubic', 'easeOutCubic' and 'easeInOutCubic'.

IndicatorPositionType

Page information display position, optional values are 'left', 'top-left', 'top', 'top-right', 'bottom-left', 'bottom', 'bottom-right' and 'right'.

SwiperList

Carousel item list configuration, including image or video address value, video cover poster, file resource type type and other attributes, supports extended attributes. After specifying type, the component will not internally determine the file type and will use type as the standard.

nameDescriptionMinimum Version
valueImage or video address-
posterVideo cover-
typeUsed to specify file resource type, optional values image, video1.4.0

SwiperIndicatorProps

ParameterDescriptionTypeOptional ValuesDefault ValueMinimum Version
currentCurrent carousel item (index)Number-00.1.22
directionCarousel sliding directionDirectionTypehorizontal, verticalhorizontal0.1.22
min-show-numWon't show navigator below this numberNumber-20.1.22
pagination-positionPage information display positionIndicatorPositionTypeleft, top-left, top, top-right, bottom-left, bottom, bottom-right, rightbottom0.1.22
show-controlsWhether to show control buttonsBoolean-false0.1.22
totalTotal number of itemsNumber-00.1.22
typeNavigator typeSwiperIndicatorTypedots, dots-bar, fractiondots0.1.22
autoplayWhether to enable auto-playboolean-true0.1.22

Events

Event NameDescriptionParametersMinimum Version
clickTriggered when clicking carousel item(index: number, item: SwiperList | string)0.1.22
changeTriggered when carousel switches(current: number, source: 'autoplay' | 'touch' | 'nav')0.1.22

Slot

nameDescriptionParametersMinimum Version
indicatorCustom indicator{ current: number, total: number }1.13.0
defaultItem display content`{ item: stringSwiperList, index: number }`

External Style Classes

Class NameDescriptionMinimum Version
customClassExternal custom class name0.1.22
customIndicatorClassCustom indicator class name0.1.22
customImageClassCustom image class name, will be deprecated in version 1.3, please use customItemClass instead0.1.22
customPrevImageClassCustom previous image class name, will be deprecated in version 1.3, please use customPrevClass instead0.1.22
customNextImageClassCustom next image class name, will be deprecated in version 1.3, please use customNextClass instead0.1.22
customItemClassCustom item class name1.3.13
customPrevClassCustom previous item class name1.3.13
customNextClassCustom next item class name1.3.13
customTextClassCustom text title class name1.3.13
customTextStyleCustom text title style1.3.13

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.