首页 > 其他 > 详细

vue-awesome-swiper 简单轮播图

时间:2020-07-11 17:59:10      阅读:59      评论:0      收藏:0      [点我收藏+]
先安装 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.$emit(‘itemClick‘,this.swiper.activeIndex)
            }
          }
        }
      }
    },
    methods: {
    },
    mounted() {
    }
  }

 

vue-awesome-swiper 简单轮播图

原文:https://www.cnblogs.com/rchao/p/13284325.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!