Skip to content

轮播 Swiper

轮播组件。

重要提示

重要提示

需在 App.vue 中引入 pure-styles 样式,@import '@/uni_modules/pure-styles/index.css';

兼容性

  • 兼容:✅
  • 不兼容:❌
  • 未知:❔
H5安卓苹果微信支付宝百度抖音QQ快手飞书京东
小红书鸿蒙360华为快应用快应用联盟

插件市场地址

DCloud 插件市场地址

基础使用

数据驱动方式

  • 通过 list 属性设置数据。
  • 通过 current 属性设置当前索引。
  • 通过 @change 事件监听切换事件,监听到切换事件后。获取新的索引,最后更新索引。
vue
<template>
    <pure-swiper
        :list="list"
        :current="current"
        @change="(e) => (current = e.detail.current)"
    ></pure-swiper>
</template>

自定义内容方式

提示

此种方式也需要给组件传递 listcurrent 属性。

vue
<template>
    <pure-swiper :list="list" :current="current" @change="handleChange">
        <swiper-item class="swiper-item" v-for="(_item, _index) in list" :key="_index">
            <view class="swiper-item-content">
                <pure-image
                    :src="_item.src"
                    :placeholder="_item.src"
                    mode="aspectFill"
                    width="100%"
                    height="100%"
                ></pure-image>
            </view>
        </swiper-item>
    </pure-swiper>
</template>

指示器

  • 通过 indicator 属性设置是否显示指示器。
  • 通过 indicatorMode 属性设置指示器模式。
vue
<template>
    <pure-swiper
        :list="list"
        :current="current"
        indicator
        indicatorMode="bar"
    ></pure-swiper>
</template>

切换按钮

  • 通过 arrow 属性设置是否显示切换按钮。
vue
<template>
    <pure-swiper
        :list="list"
        :current="current"
        arrow
    ></pure-swiper>
</template>

Props

属性名说明类型默认值可选值版本
list数据Array[]-+1.0.0
current激活项下标Number0-+1.0.0
mediaKey媒体资源的路径字段名,同 <pure-image> 组件的 [src](./image.md#props) 属性Stringsrc-+1.0.0
placeholderKey占位媒体资源的路径字段名,同 <pure-image> 组件的 [placeholder](./image.md#props) 属性Stringplaceholder-+1.0.0
mediaMode媒体资源的裁剪模式,同 <pure-image> 组件的 [mode](./image.md#props) 属性Stringplaceholder-+1.0.0
indicator是否显示指示器Booleanfalse-+1.0.0
indicatorMode指示器模式,同 <pure-indicator> 组件的 [mode](./indicator.md#props) 属性Stringdotbar、line、number、index、title、progress+1.0.0
separatornumber 指示器的分隔符,同 <pure-indicator> 组件的 [separator](./indicator.md#props) 属性String/-+1.0.0
titleKeytitle 指示器的字段名,同 <pure-indicator> 组件的 [titleKey](./indicator.md#props) 属性Stringtitle-+1.0.0
indicatorHoverClass指示器的 hover-class,同 <pure-indicator> 组件的 [hoverClass](./indicator.md#props) 属性Stringundefined-+1.0.0
arrow是否显示切换按钮Booleanfalse-+1.0.0
prevIcon后退按钮的图标名称,同 <pure-prev-next> 组件的 [prevIcon](./prev-next.md#props) 属性Stringundefined-+1.0.0
nextIcon前进按钮的图标名称,同 <pure-prev-next> 组件的 [nextIcon](./prev-next.md#props) 属性Stringundefined-+1.0.0
arrowDisabledClass切换按钮禁用时的 class,同 <pure-prev-next> 组件的 [disabledClass](./prev-next.md#props) 属性Stringundefined-+1.0.0
arrowHoverClass切换按钮的 hover-class,同 <pure-prev-next> 组件的 [hoverClass](./prev-next.md#props) 属性Stringundefined-+1.0.0
disabledClassswiper item 禁用时的 classStringpure-disabled-+1.0.0
activedClassswiper item 激活时项 classStringpure-swiper-item-actived-+1.0.0
inactivedClassswiper item 未激活项的 classStringpure-swiper-item-inactived-+1.0.0
formatItemClassswiper item 自定义 class 格式化函数,在自定义个性化轮播时用来给不同的 swiper item 设置不同的 classFunctionnull-+1.0.0
imageOpts图片的其他配置,同 <pure-image> 组件的 [props](./image#props)Objectnull-+1.0.0
width轮播宽度,注意:只是轮播宽度,如果指示器或者切换按钮设置为静态布局,不会占用此宽度String--+1.0.0
height轮播高度,注意:只是轮播高度,如果指示器或者切换按钮设置为静态布局,不会占用此高度String--+1.0.0
<swiper> 组件的原生属性参考---+1.0.0

Event

事件名说明回调参数版本
change切换事件event: event.detail = {current: current, source: source}+1.0.0
transitionswiper-item 的位置发生改变时会触发 transition 事件event: event.detail = {dx: dx, dy: dy},支付宝小程序暂不支持dx, dy+1.0.0
animationfinish动画结束时会触发 animationfinish 事件event: event.detail = {current: current, source: source}+1.0.0
itemClickswiper item 点击事件index: 被点击项的下标。item: 被点击项的数据。+1.0.0
prev后退按钮点击事件index: 后退后的新下标。+1.0.0
next前进按钮点击事件index: 前进后的新下标。+1.0.0
indicatorItemClick指示器 item 点击事件index: 被点击 item 的下标+1.0.0

Slots

名称说明参数版本
default默认,自定义 item-+1.0.0
indicator自定义指示器-+1.0.0
arrow自定义切换按钮-+1.0.0

基于 MIT 许可发布