vue swiper banner组件

基于vue2版本

建议安装偶数位 node-v14.x

建议安装node版本管理器nvm

swiper组件官网

效果图展示
在这里插入图片描述

1.项目中安装swiper

npm i wiper@5.4.5

2.对应页面使用

<template>
  <div>
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="(item, index) in bannerList" :key="index">
          <img :src="item" alt="">
        </div>
      </div>
      <!-- 分页器 -->
      <div class="paginationBox">
        <div class="swiper-pagination"></div>
      </div>
    </div>
  </div>
</template>

<script>
import Swiper from 'swiper'
import 'swiper/css/swiper.min.css'
export default {
  data() {
    return {
      bannerList: [
        'https://图片地址',
        'https://图片地址'
      ]
    }
  },
  mounted() {
    this.getBanner()
  },
  methods: {
    getBanner() {
    	//获取图片request 回调之后 注册swiper
      new Swiper('.swiper-container', {
        autoplay: true,//自动播放
        speed:2000,//播放速度
        loop: true,//无缝
        pagination: {//是否展示页码
          el: '.swiper-pagination',//页码容器
          clickable :true,//是否可以点击页码切换
        },
      })
    }
  }
}
</script>

<style lang="less" scoped>
.swiper-slide {
  height: 480px;

  img {
    width: 100%;
    height: 480px;
    object-fit: cover;
  }
}

.paginationBox {
  position: absolute;
  bottom: 0;
  display: flex;
  justify-content: center;
  width: 100%;
  height: 20px;
  z-index: 3;
}

.swiper-pagination {
  display: flex;
  background: rgba(255, 255, 255, 0.3);//页码默认小圆点颜色
  border-radius: 6px;
  padding: 2px 5px;
  margin: 0 auto;

  /deep/.swiper-pagination-bullet {
    display: block;
    margin: 0 2px;
    background-color: #fff;//页码背景色
  }

  /deep/.swiper-pagination-bullet-active {
    background-color: #F71D0C;//选中小圆点颜色
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值