zoukankan      html  css  js  c++  java
  • vue-awesome-swiper 简单轮播图

    先安装 npm install swiper vue-awesome-swiper --save
    这里使用的swiper使用的是swiper5.x版本   使用6.x分页器不显示,很多配置都没有效果
    使用全局引入 

    import VueAwesomeSwiper from 'vue-awesome-swiper'
    import 'swiper/css/swiper.css'
    Vue.use(VueAwesomeSwiper)
    
    
    局部引入
    import {Swiper, SwiperSlide} from 'vue-awesome-swiper'
    import 'swiper/css/swiper.css'

    界面

    <template>
      <swiper ref="mySwiper" :options="swiperOptions">
        <swiper-slide v-for="(item,index) of banners" :key="index">
          <img :src="item.icon" ref="icon">
        </swiper-slide>
        <div class="swiper-pagination" slot="pagination"></div>
      </swiper>
    </template>
    
    <style scoped>
      .swiper-slide {
        width: 100%;
        height: 100%;
        overflow: hidden;
      }
    
      .swiper-slide img {
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
    
      .swiper-container {
        /*--swiper-theme-color: #ff6600;*/
        --swiper-pagination-color: #00ff33; /* 两种都可以 */
      }
    </style>

    js代码

    //import {Swiper, SwiperSlide} from 'vue-awesome-swiper'
      //import 'swiper/css/swiper.css'
    
      export default {
        name: "Banner",
        // components: {
        //   Swiper,
        //   SwiperSlide
        // },
        computed: {
          swiper() {
            return this.$refs.mySwiper.$swiper
          }
        },
        props: {
          banners: {
            type: Array,
            default() {
              return []
            }
          }
        },
        data() {
          return {
            swiperOptions: {
              pagination: {
                el: '.swiper-pagination',
                clickable: true,
                type: 'bullets'
              },
              init: true,
              loop: true,
              initialSlide: 0,
              autoplay: {
                delay: 5000,
                disableOnInteraction: false
              },
              speed: 800,
              direction: "horizontal",
              on: {
                click: () => {
                  //this.swiper.realIndex 选中的索引(对应我们传入的banners集合)
                  //loop为true时轮播图前后会添加滑动时的占位图片
                  //所以会多出2张图片 这里的索引就和数据对应不上了
                  //所以需要使用realInedx
                  //this.swiper.activeIndex 选中的索引(这里是当前真实dom的索引)
                  this.$emit('itemClick',this.swiper.realIndex)
                }
              }
            }
          }
        },
        methods: {
        },
        mounted() {
        }
      }
  • 相关阅读:
    Ranorex发布2.3版本支持Flex4
    TestComplete基础教程
    2009年缺陷跟踪和测试管理工具使用情况调查报告
    软件自动化测试资源列表
    TestComplete资源列表
    分治算法
    画表格蓝桥杯
    分红酒蓝桥杯
    “硬币方案”蓝桥杯
    微生物增值蓝桥杯
  • 原文地址:https://www.cnblogs.com/rchao/p/13284325.html
Copyright © 2011-2022 走看看