查看: 35|回复: 0

uni-app 实现轮播图 【数字胶囊】

[复制链接]

2

主题

0

回帖

0

积分

热心网友

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2009-10-30
发表于 2020-11-13 12:04:00 | 显示全部楼层 |阅读模式

官网:https://uniapp.dcloud.io/component/swiper

效果图:

  

<view class="swiper">
    <swiper :interval="3000" :duration="1000" :indicator-dots="false"
     :current="topSwiperIndex" @change="topSwiperTab">
        <swiper-item v-for="(item,index) in topSwiper" :key="index">
            <view class="swiper-item">
                <image :src="item.src" mode="aspectFill"></image>
            </view>
        </swiper-item>
    </swiper>

    <!-- 自定义指示点dots -->
    <view class="dots">
        <text>{{topSwiperIndex+1}}/{{topSwiper.length}}</text>
    </view>
</view>

 

data() {
    return {
        topSwiperIndex: 0,
        topSwiper: [
            {
                src: require('../../static/images/1.jpg')
            },
            {
                src: require('../../static/images/1.jpg')
            },
            {
                src: require('../../static/images/1.jpg')
            },
            {
                src: require('../../static/images/1.jpg')
            },
            {
                src: require('../../static/images/1.jpg')
            }
        ] 
    };
},

 

methods:{
    topSwiperTab(e) {
        var that = this;
        this.topSwiperIndex = Number(e.target.current);
    }
}

注:swiper轮播图的默认高度是150px,通常我们的轮播图片高度不是这个。

解决办法:

指定swiper标签的宽高,然后在指定image图片的宽高

swiper{
    width: 100%;
    height: 777.17rpx;
    
    swiper-item{

        image {
            width: 100%;
            height: 781.7rpx;
            display: block;
        }
    }
}

拓展:uni-app实现轮播图自定义小圆点



来源:https://www.cnblogs.com/hellocd/p/13968682.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部