vue 使用Swiper.js 实现轮播 ,中间图还在两边显示一小段上下图

47 篇文章 0 订阅

首先得安装依赖 再引入Swiper.js 。
在main.js 引入
// swiper 轮播样式
import “swiper/swiper-bundle.min.css”;

分装组件页面

<template>
     <!-- 轮播组件 -->
    <div class="swiper_banner">
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <div class="swiper-slide" v-for="(val,index) in bannerDataList" :key="index">
                   <a :href="val.link">
                     <img class="item_img" :src="val.imgUrl" alt />
                    </a>
                 </div>
                <!-- <div class="swiper-slide"><img src="@/assets/sandai_banner.png" /></div>
                <div class="swiper-slide"><img src="@/assets/zhaungxiu.png" /></div>
                <div class="swiper-slide"><img src="@/assets/eankang.png" /></div> -->
            </div>
            <!-- 如果需要分页器 -->
            <div class="swiper-pagination"></div>
        </div>
    </div>
</template>

<script>
//   import Swiper from "swiper";
// import {bannerData} from "../dictionary/supermarket";
import Swiper from "swiper/swiper-bundle.min.js"
    export default {
       props: {
          bannerData: { // 数据参数
            type: Array,
            default() {
              return []
            }
            }
        },
        data() {
            return {
                bannerDataList: this.bannerData, // 广告横幅图
            }
        },
        mounted () {
            this.$nextTick(()=>{
                new Swiper ('.swiper-container', {
                        direction: 'horizontal',
                        loop: true, // 是否无效循环
                        autoplay: { // 自动轮播效果
                            delay:3000,
                            disableOnInteraction: false,
                            },
                        slidesPerView: "auto",
                        centeredSlides:true,
                        spaceBetween: 15, // 图片的边距
                        // 如果需要分页器
                        pagination: {
                            el: '.swiper-pagination'
                            }
                    })
            })
        },
        methods: {
            name() {
                
            }
        },
    }
</script>

<style lang="less">
    .swiper_banner{
        .swiper-container {
        //  margin-top: 0.2rem;
        width: 100%;
        height: 2.6rem;
        overflow: visible !important;
        position: relative;
        }

        .swiper-container .swiper-wrapper .swiper-slide {
        width: 6rem;
        border-radius: 0.12rem;
        //  margin-right: 0.3rem !important;
        }

        .swiper-container .swiper-wrapper .swiper-slide img {
        width: 100%;
        height: 2.6rem;
        border-radius: 0.12rem !important;
        }

        // .swiper-container .swiper-wrapper .swiper-slide-prev {
        // margin-top: 0.18rem;
        // height: 2.5rem !important;

        // }

        // .swiper-container .swiper-wrapper .swiper-slide-prev img {

        // height: 2.4rem !important;

        // }

        // .swiper-container .swiper-wrapper .swiper-slide-next {

        // margin-top: 0.18rem;

        // height: 2.5rem !important;

        // }

        // .swiper-container .swiper-wrapper .swiper-slide-next img {
        // height: 2.4rem !important;
        // }

        .swiper-container .swiper-wrapper .swiper-slide-active {
        width: 6rem;
        }
        .swiper-pagination {
        bottom: 0.1rem !important;
        }
        .swiper-pagination{
            bottom: -0.5rem !important;
        }
            // .swiper-pagination .swiper-pagination-bullet{width: 12px; height: 12px; background: #ff1e1e;}
            // .swiper-pagination .swiper-pagination-bullet-active{width: 21px; height: 12px; background: #e75230; border-radius: 6px;}
    }

</style>

在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值