Swiper轮播图

版本:“swiper”: “^6.8.4”,
处理每分钟重新请求数据后,播放卡顿,快速闪,没按照设置时间播放等bug
以下是直接vue2 完整的组件代码
使用: <SwiperV :imgList=“swiperList” /

在这里插入图片描述

<template>
    <div class="bannerBox">
        <div class="swiper-container gallery-top">
            <div class="swiper-wrapper">
                <div class="swiper-slide" v-for="(item, index) in imgList" :key="index">
                    <img class="img" :src="item" />
                </div>
            </div>
          
            <div class="swiper-button-prev swiper-button-white">
                <i class="el-icon-arrow-left"></i>
            </div>
            <div class="swiper-button-next swiper-button-white">
                <i class="el-icon-arrow-right"></i>
            </div>
        </div>
        <!-- <div style="height: 15px; width: 400px"></div>
      <div class="swiper-container gallery-thumbs">
        <div class="swiper-wrapper">
          <div class="swiper-slide swiper-bottom" v-for="(item, index) of bigImg" :key="index">
            <img class="img2" :src="item.imgPath" />
            <div class="title_text">{{ item.name }}</div>
          </div>
        </div>
      </div> -->
    </div>
</template>

<script>
import Swiper from "swiper"
// import { Pagination } from 'swiper';

export default {
    // components: { Pagination },
    props: {
        imgList: {
            type: Array,
            default: () => []
        }
    },
    data () {
        return {
            bigImg: [],
            galleryTop:null
        }
    },
    watch: {
        "imgList": {
            handler (newValue, oldValue) {
                this.$nextTick(() => {
                    this.galleryTop.destroy(); 
                    this.galleryTopLunbo()
                })
            },
            deep: true
        }
    },
    created () {

    },
    mounted () { 
        this.$nextTick(() => {
                    this.galleryTopLunbo()
                })
    },

    methods: {
        galleryTopLunbo () {
            this.galleryTop = new Swiper(".gallery-top", {
                spaceBetween: 0,
                loop: true,
                loopedSlides: 1,
                autoplay: {
                    delay: 3000,
                    stopOnLastSlide: false,
                    disableOnInteraction: false,
                },
                // 左右按钮
                navigation: {
                    nextEl: ".swiper-button-next",
                    prevEl: ".swiper-button-prev",
                },
                thumbs: {
                    //thumbs组件专门用于制作带缩略图的swiper
                    swiper: this.galleryThumbs,
                    slideThumbActiveClass: "swiper-slide-thumb-active",
                },
            })
        },
        galleryThumbsLunbo () {
            this.galleryThumbs = new Swiper(".gallery-thumbs", {
                spaceBetween: 15, //在slide之间设置距离(单位px)
                slidesPerView: 4, //设置slider容器能够同时显示的slides数量
                // loop: true,        //设置为true 则开启loop模式
                // freeMode: true,    //默认为false,普通模式:slide滑动时只滑动一格
                // loopedSlides: 7,    //一般设置大于可视slide个数2个即可
                watchSlidesVisibility: true, //开启watchSlidesVisibility选项前需要先开启watchSlidesProgress
                watchSlidesProgress: true, //开启这个参数来计算每个slide的progress(进度、进程)
            })
        },

        event () {
            const self = this
            return {}
        },
        network () {
            const self = this
            return {}
        },
    },
}
</script>

<style scoped lang="scss">
.title_text {
    width: 100%;
    text-align: center;
    color: #000;
    padding: 10px 0;
    font-size: 16px;
    font-weight: 600;
}

.bannerBox {
    width: 100%;
    height: 100%;

    .img {
        width: 100%;
        height: 100%;
    }

    .img2 {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 98%;
        height: 80%;
    }

    .gallery-top {
        width: 100%;
        height: 100%;
        border: 1px solid #ccd2e7;
    }

    .gallery-thumbs {
        width: 100%;
        height: 200px;
        background-color: #fff;

        img {
            border: 1px solid #ccd2e7;
        }
    }

    .swiper-bottom {
        opacity: 0.5;
    }

    .swiper-slide-thumb-active {
        opacity: 5;
    }
}

/deep/ .el-icon-arrow-right {
    display: none;
}

/deep/ .el-icon-arrow-left {
    display: none;
}
</style>

相关推荐

  1. Swiper

    2024-05-01 18:14:04       39 阅读
  2. Swiper后端接口实现

    2024-05-01 18:14:04       46 阅读
  3. Flutter 使用flutter_swiper_null_safety 实现

    2024-05-01 18:14:04       37 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-01 18:14:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-01 18:14:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-01 18:14:04       82 阅读
  4. Python语言-面向对象

    2024-05-01 18:14:04       91 阅读

热门阅读

  1. 自动化测试——Selenium

    2024-05-01 18:14:04       32 阅读
  2. C++临时对象的产生及优化

    2024-05-01 18:14:04       22 阅读
  3. 【Python】pandas.cut()函数的用法

    2024-05-01 18:14:04       33 阅读
  4. Python 发送钉钉消息(markdown格式)

    2024-05-01 18:14:04       35 阅读
  5. sofether重置管理员密码

    2024-05-01 18:14:04       38 阅读
  6. MySQL:DQL语句和多表设计

    2024-05-01 18:14:04       32 阅读
  7. C#的MVVM 工具包——Messenger

    2024-05-01 18:14:04       31 阅读
  8. 实现C#无标题栏窗体拖动

    2024-05-01 18:14:04       30 阅读
  9. Python模块方法总结

    2024-05-01 18:14:04       28 阅读
  10. docker seata

    2024-05-01 18:14:04       32 阅读
  11. Hadoop生态系统的核心组件探索

    2024-05-01 18:14:04       22 阅读
  12. RabbitMQ Transport indicated EOF 总结

    2024-05-01 18:14:04       31 阅读
  13. oracle的sqlplus默认会执行的脚本

    2024-05-01 18:14:04       32 阅读