Skip to content
在新窗口打开实时预览

Swiper 轮播图 ​

基于 uni-app swiper 封装,支持图片或对象数据、自定义指示器、标题和 3D 卡片效果。

平台兼容性 ​

H5App微信小程序支付宝小程序
√√√√

基础用法 ​

vue
<snake-swiper :list="['/static/a.png', '/static/b.png']" :height="360" indicator />

指示器与 3D 卡片 ​

vue
<snake-swiper :list="banners" name="image" mode="number" indicator-pos="bottomRight" effect3d show-title @change="onChange" @click="openBanner" />

对象图片依次读取 name 指定字段、src、url;标题读取 title 或 text。

ts
const banners = [
    { id: 'new', image: '/static/banner-new.png', title: '新品上市' },
    { id: 'sale', image: '/static/banner-sale.png', title: '限时活动' }
];

受控切换与自定义指示器 ​

将 current 绑定到状态可由业务主动切换轮播项;change 返回的新索引应同步回状态。indicator 插槽携带 current 与 total。

vue
<snake-swiper :list="banners" :current="current" indicator @change="current = $event">
  <template #indicator="{ current, total }">
    <view class="banner-count">{{ current + 1 }} / {{ total }}</view>
  </template>
</snake-swiper>

API ​

Props ​

参数说明类型默认值
list图片地址或对象列表Array<string | object>[]
current / height当前索引、轮播高度number | string0 / 250
autoplay / interval / duration / circular自动播放、间隔、动画时长、循环boolean | numbertrue / 3000 / 300 / true
indicator是否显示自定义指示器;也兼容配置对象boolean | object{}
moderound/dot/rect/line/numberstringround
indicatorPostopLeft/topCenter/topRight/bottomLeft/bottomCenter/bottomRightstringbottomCenter
indicatorColor / indicatorActiveColor普通和激活指示器颜色string半透明白 / 白色
name对象图片字段stringimage
radius / borderRadius圆角,borderRadius 优先string | number8
previousMargin / nextMargin前后边距string0px
effect3d / effect3dPreviousMargin3D 卡片及露出边距boolean | UnitValuefalse / 50
imgMode图片裁剪模式stringaspectFill
showTitle / title / titleStyle标题显示、兼容别名和样式boolean | stylefalse
bgColor / customClass / customStyle背景与自定义样式string | object | array主题默认值

Events ​

事件名触发时机参数
change当前项变化current: number
animationfinish动画结束{ current, source? }
click点击轮播项index: number

Slots ​

插槽名说明
indicator替换内置指示器,参数为 { current, total }

主题变量 ​

组件未直接使用 CSS 主题变量。可通过 indicatorColor、indicatorActiveColor、bgColor 和 customStyle 调整视觉样式。

为 uni-app 商城与 CMS 场景设计