前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在vue中使用swiper

在vue中使用swiper

作者头像
用户4344670
发布2020-02-13 13:29:35
6220
发布2020-02-13 13:29:35
举报
文章被收录于专栏:vue的实战vue的实战
代码语言:javascript
复制
<template>
  <div class="main">
    <!-- .swiper-container  -->
    <div class="wrap">
      <img class="bgImg" src="../../../../assets/images/fffbg.png" alt />
      <swiper :options="swiperOption" ref="mySwiper">
        <swiper-slide v-for="(item,index) in swiperList " :key="index">
          <div class="img1">
            <img :src="item.img" alt />
          </div>
        </swiper-slide>
      </swiper>
    </div>
  </div>
</template>
<script>
export default {
  name: "swiperList",
  data() {
    return {
      activeId: 0, ///   当前轮播图的序号
      swiperOption: {
        slidesPerView: 3,
        spaceBetween: 20,
        centeredSlides: true,
        loop: false,
        initialSlide :1, /// 默认页

        pagination: {
          // el: ".swiper-pagination",
          // clickable: true
        },
        on: {
          
          // 当轮播时触发
          slideChange: e => {
            let swiper = this.$refs.mySwiper.swiper;
            let i = swiper.activeIndex;
            this.activeId = i;
            console.log(i); ///  轮播的序号从 0 开始
            this.$emit("handleChangeId", i);
          }
        }
      }
    };
  },
  props: {
    swiperList: {
      type: Array,
      default: () => {}
    }
  },
  methods: {
    changId() {
      console.log("kkk");
    },
    callback() {
      console.log("毁掉");
    }
  },
  created() {}
};
</script>
<style lang="less" scoped >
.main {
  padding: 0;
  // height: 6rem;
  // padding-top: 3rem;
  overflow: hidden;
  position: relative;
  top: 0;
  left: 0;
}
.main .wrap {
  width: 100%;
  padding-bottom: 0.9rem;
  .bgImg {
    display: block;
    width: 100%;
    position: absolute;
    top: 0.9rem;
    left: 0;
  }
  // height: 6rem;
  //  background: url("../../../../assets/images/fffbg.png") center -7.8rem
  //     no-repeat;
  //     padding-bottom: .3rem;
}

// swiper-slide-active
.img1 {
  width: 100%;
  height: 3.5rem;
  background-color: #999;
  background-size: cover;
  img {
    display: block;
    width: 100%;
    height: 100%;
  }
}

.img2 {
  width: 100%;
  height: 3.5rem;
  // background-color: pink;
}

.img3 {
  width: 100%;
  height: 3.5rem;
  background-color: blue;
}
.main /deep/ .swiper-slide {
  transition: 300ms;
  transform: scale(0.8);
}

.main /deep/ .swiper-slide-active {
  transform: scale(1);
}

.main /deep/ .swiper-container {
  overflow: visible;
  width: 100%;
  height: 3.5rem;
}
.main /deep/ .swiper-slide-next {
  margin-right: 0 !important;
}
</style>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档