Skip to content

Swiper 轮播

介绍

用于循环播放一组图片或内容。

基础用法

每个 SwiperItem 组件代表一张轮播卡片,通过 height 属性设置轮播高度。

html
<vd-swiper :height="200" :vertical="state.vertical" @touchmove.stop.prevent>
  <vd-swiper-item>
    <image src="图片1" mode="aspectFill" style="width:100%;height:100%;" />
  </vd-swiper-item>
  <vd-swiper-item>
    <image src="图片2" mode="aspectFill" style="width:100%;height:100%;" />
  </vd-swiper-item>
  <vd-swiper-item>
    <image src="图片3" mode="aspectFill" style="width:100%;height:100%;" />
  </vd-swiper-item>
</vd-swiper>

纵向滚动

通过 vertical 属性设置纵向滚动。

html
<vd-swiper :height="200" vertical @touchmove.stop.prevent>
  <vd-swiper-item>1</vd-swiper-item>
  <vd-swiper-item>2</vd-swiper-item>
  <vd-swiper-item>3</vd-swiper-item>
</vd-swiper>

指示器样式

通过 indicator-type 属性设置指示器样式,可选值为 dots dots-bar page

html
<vd-swiper :height="200" indicator-type="page" @touchmove.stop.prevent>
  <vd-swiper-item>1</vd-swiper-item>
  <vd-swiper-item>2</vd-swiper-item>
  <vd-swiper-item>3</vd-swiper-item>
</vd-swiper>

指示器位置

通过 indicator-position 属性设置指示器位置,可选值为 bottom bottom-left bottom-right top top-left top-right right right-top right-bottom left left-top left-bottom right

html
<vd-swiper
  :height="200"
  indicator-type="page"
  indicator-position="bottom-right"
  @touchmove.stop.prevent
>
  <vd-swiper-item>1</vd-swiper-item>
  <vd-swiper-item>2</vd-swiper-item>
  <vd-swiper-item>3</vd-swiper-item>
</vd-swiper>

自动高度

通过 autosize 属性设置自动高度,设置后切换时会根据下一张卡片的高度自动调整。

html
<vd-swiper autosize @touchmove.stop.prevent>
  <vd-swiper-item>1</vd-swiper-item>
  <vd-swiper-item>2</vd-swiper-item>
  <vd-swiper-item>3</vd-swiper-item>
</vd-swiper>

绑定激活项

通过 active 绑定轮播当前的激活索引。

html
<vd-swiper v-model:active="active" @touchmove.stop.prevent>
  <vd-swiper-item>1</vd-swiper-item>
  <vd-swiper-item>2</vd-swiper-item>
  <vd-swiper-item>3</vd-swiper-item>
</vd-swiper>
ts
const active = ref(0);

API

Swiper Props

参数说明类型默认值
active激活索引number0
height轮播高度string | number-
autosize是否自适应轮播高度booleantrue
vertical是否纵向轮播booleanfalse
autoplay自动轮播间隔,0 时禁用string | number5000
duration切换动画时长number500
loop是否循环播放booleantrue
swipeable是否可滑动booleantrue
swipe-limit滑动限制string | number-
indicator是否展示指示器booleantrue
indicator-type指示器类型SwiperIndicatorTypedots
indicator-position指示器位置SwiperIndicatorPosition横向滚动:'bottom' 垂直滚动:'right'

SwiperItem Props

参数说明类型默认值
index索引,小程序下循环列表时需要设置该值string | number-

代替原始 Props

参数说明类型默认值
custom-id根节点idstring-
custom-class根节点类名ClassValue-
custom-style根节点样式StyleValue-

Swiper Events

事件名说明回调参数
click点击时触发MouseEvent

SwiperItem Events

事件名说明回调参数
click点击时触发MouseEvent

Swiper Slots

名称说明
default轮播卡片内容
indicator-page页码指示器内容

SwiperItem Slots

名称说明
default自定义内容

Swiper Expose

方法名说明参数返回值
prev切换上一个--
next切换下一个--
swipeTo切换到指定索引index: number-

赣ICP备2025061025号-1