vue实现带缩略图的轮播图效果

 更新时间:2024年02月01日 10:01:36   作者:lllomh  
这篇文章主要为大家详细介绍了如何使用vue实现带缩略图的轮播图效果,文中的示例代码讲解详细,具有一定的借鉴价值,有需要的可以参考下

1.引入swiper和vue-awesome-swiper插件

npm install swiper@4 --save
npm install vue-awesome-swiper@3 --save

2.在main.js中引入:

import VueAwesomeSwiper from 'vue-awesome-swiper'
 Vue.use(VueAwesomeSwiper)
 import '../node_modules/swiper/dist/css/swiper.css'

3.使用:

template:布局

<template>
  <div>
    <div class="thumb-example">
      <!-- swiper1 -->
      <swiper
              class="swiper gallery-top"
              :options="swiperOptionTop"
              ref="swiperTop"
      >
        <swiper-slide class="slide-1" v-for="item in bigImg" :key="item.id">
          <img :src="item.url" style="height:570px;width:100%" alt="" />
        </swiper-slide>
        <div
                class="swiper-button-next swiper-button-white"
                slot="button-next"
        ></div>
        <div
                class="swiper-button-prev swiper-button-white"
                slot="button-prev"
        ></div>
      </swiper>
      <!-- swiper2 Thumbs -->
      <swiper
              class="swiper gallery-thumbs"
              :options="swiperOptionThumbs"
              ref="swiperThumbs"
      >
        <swiper-slide
                class="slide"
                style="width:100px;height:100px;"
                v-for="item in bigImg"
                :key="item.id"
        >
          <img style="width:100px;height:100px;" :src="item.url" alt="" />
        </swiper-slide>
        <div class="swiper-button-next swiper-button-white" slot="button-next">
          <div>
            <img src="../assets/ArtIcon-offs.svg" alt="" />
          </div>
        </div>
        <div class="swiper-button-prev swiper-button-white" slot="button-prev">
          <div>
            <img src="../assets/ArtIcon-offs.svg" alt="" />
          </div>
        </div>
      </swiper>
    </div>
  </div>
</template>
 
<script>
export default {
  mounted() {
    // 实现swiper双向控制
    this.$nextTick(() => {
      const swiperTop = this.$refs.swiperTop.swiper
      const swiperThumbs = this.$refs.swiperThumbs.swiper
      swiperTop.controller.control = swiperThumbs
      swiperThumbs.controller.control = swiperTop
    })
  },
  data() {
    return {
      //轮播大图配置
      bigImg: [
        {
          url: 'https://bhw.lllomh.com/images/02.jpg',
          id: 0
        },
        {
          url: 'https://bhw.lllomh.com/images/01.jpg',
          id: 1
        },
        {
          url: 'https://bhw.lllomh.com/images/03.jpg',
          id: 2
        },
        {
          url: 'https://bhw.lllomh.com/images/04.jpg',
          id: 3
        }
      ],
      swiperOptionTop: {
        zoom: true,
        loop: true,
        loopedSlides: 5, // looped slides should be the same
        spaceBetween: 10,
        observer: true, //修改swiper自己或子元素时,自动初始化swiper
        observeParents: true, //修改swiper的父元素时,自动初始化swiper
        // autoplay: {  //自动轮播
        //   delay: 2000,
        //   disableOnInteraction: false
        // },
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        }
      },
      swiperOptionThumbs: {
        loop: true,
        loopedSlides: 5, // looped slides should be the same
        spaceBetween: 10,
        centeredSlides: true,
        slidesPerView: 'auto',
        touchRatio: 0.2,
        slideToClickedSlide: true,
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        }
      }
    }
  },
 
  methods: {}
}
</script>

4.scss or sass

<style lang="scss" scoped>
h3 {
  margin: 20px 0 0 10px;
}
.thumb-example {
  width: 864px;
  margin-top: 20px;
  // background: #000;
}
.swiper-slide {
  background-size: cover;
  background-position: center;
}
.gallery-top {
  // height: 80% !important;
  height: 600px;
  width: 100%;
}
.gallery-thumbs {
  height: 20% !important;
  box-sizing: border-box;
  padding: 10px 0px;
  width: 864px;
  margin-left: 2px;
  .swiper-button-next {
    right: 0px;
  }
  .swiper-button-prev {
    left: 0px;
  }
  .swiper-button-next,
  .swiper-button-prev {
    background: #fff;
    width: 45px;
    text-align: center;
    height: 101px;
    top: 26%;
    div {
      margin-top: 30px;
      background: rgb(207, 205, 205);
      height: 45px;
      border-radius: 50%;
      img {
        margin: 7px 0 0 2px;
        width: 30px;
      }
    }
  }
  .swiper-button-next:hover div {
    background: rgb(189, 186, 186);
  }
  .swiper-button-prev:hover div {
    background: rgb(189, 186, 186);
  }
}
.gallery-thumbs .swiper-slide {
  width: 20%;
  height: 80px;
  // opacity: 0.4;
}
.gallery-thumbs .swiper-slide-active {
  border: 2px solid red;
}
</style>

这样就可以了

效果:

到此这篇关于vue实现带缩略图的轮播图效果的文章就介绍到这了,更多相关vue带缩略图轮播内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • vue菜单栏联动内容页面tab的实现示例

    vue菜单栏联动内容页面tab的实现示例

    本文主要介绍了vue菜单栏联动内容页面tab的实现示例,左侧菜单栏与右侧内容部分联动,当点击左侧的菜单,右侧会展示对应的tab,具有一定的参考价值,感兴趣的可以了解一下
    2024-01-01
  • vue项目配置同一局域网可使用ip访问的操作

    vue项目配置同一局域网可使用ip访问的操作

    这篇文章主要介绍了vue项目配置同一局域网可使用ip访问的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-10-10
  • Vue项目导入导出文件功能以及导出文件后乱码问题及解决

    Vue项目导入导出文件功能以及导出文件后乱码问题及解决

    这篇文章主要介绍了Vue项目导入导出文件功能以及导出文件后乱码问题及解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-09-09
  • Vue组件之间的参数传递与方法调用的实例详解

    Vue组件之间的参数传递与方法调用的实例详解

    这篇文章主要介绍了Vue组件之间的参数传递与方法调用,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-12-12
  • vue前端开发keepAlive使用详解

    vue前端开发keepAlive使用详解

    在开发中经常有从列表跳到详情页,然后返回详情页的时候需要缓存列表页的状态(比如滚动位置信息),这个时候就需要保存状态,要缓存状态
    2021-10-10
  • vue给组件传递不同的值方法

    vue给组件传递不同的值方法

    今天小编就为大家分享一篇vue给组件传递不同的值方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-09-09
  • 关于vue利用postcss-pxtorem进行移动端适配的问题

    关于vue利用postcss-pxtorem进行移动端适配的问题

    这篇文章主要介绍了关于vue利用postcss-pxtorem进行移动端适配的问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-11-11
  • Vue API中setup ref reactive函数使用教程

    Vue API中setup ref reactive函数使用教程

    setup是用来写组合式api,内部的数据和方法需要通过return之后,模板才能使用。在之前vue2中,data返回的数据,可以直接进行双向绑定使用,如果我们把setup中数据类型直接双向绑定,发现变量并不能实时响应。接下来就详细看看它们的使用
    2022-12-12
  • Vue.js中vue-property-decorator的使用方法详解

    Vue.js中vue-property-decorator的使用方法详解

    vue-property-decorator是一个用于在Vue.js中使用TypeScript装饰器的库,它能够简化 Vue 组件的定义,使代码更加简洁和可维护,它能够简化Vue组件的定义,使代码更加简洁和可维护,本文将深入探讨vue-property-decorator的使用方法,并展示如何在Vue.js项目中应用它
    2024-08-08
  • vue3实现图片瀑布流展示效果实例代码

    vue3实现图片瀑布流展示效果实例代码

    这篇文章主要介绍了vue3实现图片瀑布流展示效果的相关资料,该组件可以调整列数、支持懒加载、自定义每页滚动数量、高度和点击效果,作者展示了组件的效果,并详细说明了实现方法,包括组件的创建和依赖的工具库,需要的朋友可以参考下
    2024-11-11

最新评论