更新记录

1.0.1(2024-06-25)

新增clickItem

1.0.0(2024-06-25)

第一版


平台兼容性

Vue2 Vue3
×
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.1.0 app-vue
钉钉小程序 快手小程序 飞书小程序 京东小程序
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari

swiper/banner

组件支持插槽,需要依赖 scss 插件, 或自己去手动修改css样式(很简单)

属性 Props

属性名 类型 默认值 说明
items Array [ ] 为swiper显示所需的数据,数据格式见下方示例
height String '350rpx' swiper高度
swiperConfig Object swiperConfig swiper配置数据,同swiper组件
showBg Boolean false 是否显示毛玻璃背景
scale Number/String 0.9 缩小比例 0-1
offsetMargin String '0' 偏移量

说明

通过 scale、offsetMargin 调整滑块间距

swiperConfig

属性名 类型 默认值 说明
indicatorDots Boolean false 是否显示面板指示点
indicatorColor String 'rgba(255, 255, 255, .4)' 指示点颜色
indicatorActiveColor String 'rgba(255, 255, 255, 1)' 当前选中的指示点颜色
autoplay Boolean false 是否自动切换
interval Number 3000 自动切换时间间隔
duration Number 300 滑动动画时长
circular Boolean true 是否采用衔接滑动,即播放到末尾后重新回到开头
previousMargin String '60rpx' 前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值
nextMargin String '60rpx' 后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值

插槽 --- 不支持小程序

属性名 类型 说明
index Number 索引
data Object 数据项

方法 Events

属性名 返回值 说明
change event.detail = {current: current, source: source} current 改变时会触发
transition event.detail = {current: current, source: source} swiper-item 的位置发生改变时会触发
animationfinish event.detail = {dx: dx, dy: dy} 动画结束时会触发
clickItem {detail: {}, index: 0} 点击滑块会触发

示例

<template>
    <view class="index">
        <view class="group">
            <view class="title">组件 示例</view>
            <wyh-swiper-demo1 
            :height="height"
            :items="banner" 
            :swiperConfig="swiperConfig" 
            :scale="scale" 
            :offsetMargin="offsetMargin+'rpx'" 
            :showBg="showBg" 
            @change="swiperChange"
            />
            <view class="p">
                <view class="l">显示背景(showBg)</view>
                <view class="r">
                    <switch :checked="showBg" @change="onShowBg"/>
                </view>
            </view>
            <view class="p">
                <view class="l">缩放大小(scale)</view>
                <view class="r" style="width: 70%;">
                    <slider :min="70" :show-value="true" block-size="18" :value="scale*100" @changing="changScale"/>
                </view>
            </view>
            <view class="p">
                <view class="l">偏移量(offsetMargin)</view>
                <view class="r" style="width: 30%;">
                    <uni-easyinput type="number" v-model="offsetMargin" placeholder="0" />
                </view>
            </view>
        </view>
        <view class="group">
            <view class="title">slot 示例</view>
            <wyh-swiper-demo1 :items="banner" :height="height" :swiperConfig="swiperConfig" :scale="scale" :offsetMargin="offsetMargin+'rpx'">
                <template v-slot="slotProps">
                    <image class="img" :style="{height: height}" :src="slotProps.data.path" mode="aspectFill"></image>
                    <view class="path">{{slotProps.index}}: {{slotProps.data.path}}</view>
                </template>
            </wyh-swiper-demo1>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                banner: [],
                height: '350rpx',
                swiperConfig: {
                    indicatorDots: false,
                    indicatorColor: 'rgba(255, 255, 255, .4)',
                    indicatorActiveColor: 'rgba(255, 255, 255, 1)',
                    autoplay: false,
                    interval: 3000,
                    duration: 300,
                    circular: true,
                    previousMargin: '100rpx',
                    nextMargin: '100rpx'
                },
                showBg: false,
                scale: 0.9,
                offsetMargin: 0
            }
        },
        methods: {
            // current 改变时会触发
            swiperChange (e) {
                console.log('change', e)
            },
            onShowBg(ret) {
                this.showBg = ret.detail.value;
            },
            changScale(ret) {
                this.scale = ret.detail.value/100;
            },
            getBanner() {
                setTimeout(() => {
                    this.banner = [{
                        path: 'https://picsum.photos/id/110/600/300'
                    },{
                        path: 'https://picsum.photos/id/210/600/300'
                    },{
                        path: 'https://picsum.photos/id/310/600/300'
                    },{
                        path: 'https://picsum.photos/id/410/600/300'
                    },{
                        path: 'https://picsum.photos/id/510/600/300'
                    }]
                }, 300)
            }
        },
        onLoad() {
            this.getBanner()
        }
    }
</script>

<style lang="scss" scoped>
    .index {
        min-height: calc(100vh - var(--window-top));
        .group {
            padding: 30rpx 0;
            .title {
                text-align: center;
                font-size: 32rpx;
                font-weight: bold;
                color: #333;
                padding: 20rpx;
            }
            .p {
                display: flex;
                flex-direction: row;
                justify-content: space-between;
                padding: 20rpx;
            }
        }
        /deep/ .wyh_swiper {
            .scale_box {
                position: relative;
            }
            .img {
                display: block;
                width: 100%;
            }
            .path {
                position: absolute;
                bottom: 0;
                left: 0;
                width: 100%;
                box-sizing: border-box;
                padding: 10rpx 20rpx;
                background: rgba(255,255,255,0.9);
                color: #000;
                font-weight: bold;
                font-size: 24rpx;
            }
        }
    }
</style>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问