swiper轮播图在vue中实现显示3张图片,一个完整的两边显示一半

这里是引用https://blog.csdn.net/weixin_44237806/article/details/100141698

安装

 yarn add swiper vue-awesome-swiper

引用

局部引用
import Swiper from 'swiper/swiper-bundle.min.js'
import 'swiper/swiper-bundle.min.css'

有个坑,在本地OK,在线上就会加载不到css,我就简单粗暴的把css文件提了出来,放在assets/css/下面

swiper效果图,图片路径自己更改吧
这个
swiper轮播图在vue中实现显示3张图片,一个完整的两边显示一半_第1张图片

<template>
    <div id="root" style="overflow: hidden">
      <div class="swiper-container" >
        <div class="swiper-wrapper" >
          <div class="swiper-slide" ><img src="../assets/logo.png" />div>
          <div class="swiper-slide" ><img src="../assets/logo.png" />div>
          <div class="swiper-slide" ><img src="../assets/logo.png" />div>
          <div class="swiper-slide" ><img src="../assets/logo.png" />div>
          <div class="swiper-slide" ><img src="../assets/logo.png" />div>
        div>
      div>
    div>
template>

<script>

  export default {
    components: {

    },
    data(){
      return {
        }
    },
    mounted(){
      this.$nextTick(()=>{
        new Swiper('.swiper-container', {
          loop: true, // 循环模式选项
          loopedSlides: 5,
          // 如果需要分页器
          // pagination: {
          //   el: '.swiper-pagination',
          // },
        })
      })

    }
  }
script>

<style >
  .swiper-container {
    overflow: visible!important;
    width: 600px;
    height: 300px;
  }
  .swiper-container .swiper-wrapper .swiper-slide{ width: 600px; border-radius: 20px;background: palegreen}
  .swiper-container .swiper-wrapper .swiper-slide img{ border-radius: 20px;}
  .swiper-container .swiper-wrapper .swiper-slide-prev{ margin-top: 18px; height: 284px!important;}
  .swiper-container .swiper-wrapper .swiper-slide-prev img{ height: 284px!important;}
  .swiper-container .swiper-wrapper .swiper-slide-next{ margin-top: 18px; height: 284px!important;}
  .swiper-container .swiper-wrapper .swiper-slide-next img{ height: 284px!important;}
  .swiper-container .swiper-wrapper .swiper-slide-active{ width: 600px;margin-right: 10px;margin-left: 10px}

style>


要实现三张图片等高,删除这几行代码就可以啦

  .swiper-container .swiper-wrapper .swiper-slide-prev{ margin-top: 18px; height: 284px!important;}
  .swiper-container .swiper-wrapper .swiper-slide-prev img{ height: 284px!important;}
  .swiper-container .swiper-wrapper .swiper-slide-next{ margin-top: 18px; height: 284px!important;}
  .swiper-container .swiper-wrapper .swiper-slide-next img{ height: 284px!important;}

swiper轮播图在vue中实现显示3张图片,一个完整的两边显示一半_第2张图片

你可能感兴趣的:(#,Vue,#,CSS,大前端,html,vue.js,html5,javascript)