vue使用原生swiper代码实例

发布时间:2020-09-10 03:02:31 作者:古墩古墩
来源:脚本之家 阅读:246

这篇文章主要介绍了vue使用原生swiper代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

代码如下

<template>
  <div>
    <div class="swiper_Box" :class="identify">
      <div class="swiper-wrapper" :ref="identify">
        <div class="swiper-slide" v-for="(item,index) in imgArr" :key="'swiperSlide'+index">
          <div class="bannerItem">
            <img :src="item.url" alt="">
          </div>
        </div>
      </div>
      <!-- <div v-if="imgArr.length>1" class="swiper-button-prev" slot="button-prev"></div>
      <div v-if="imgArr.length>1" class="swiper-button-next" slot="button-next"></div> -->
      <div class="swiper-pagination"></div>
    </div>
  </div>
</template>

<script>
export default {
  props:['imgArr','identify','paginationType'],//接收传来的轮播图
  watch:{
    imgArr:{
      handler(newVal){
        console.log(newVal)
      },
      immediate:true
    },
    identify:{
      handler(newVal){
        console.log("id:"+newVal)
        var self=this;
      },
      immediate:true 
    }
  },
  data(){
    return{
      swiperShow:false,
      MySwiper:null,//swiper实例
    }
  },
  created(){
  },
  mounted(){
    var self=this;
    self.MySwiper = new Swiper ('.'+self.identify,{
      init: true,
      observer:true,
      observeParents:true,
      slidesPerView: 1,
      spaceBetween: 0,
      keyboard: {
        enabled: true,
      },
      loop: true,
      autoplay: {
        delay: 8000,
        disableOnInteraction: false
      },
      pagination: {
        el: '.swiper-pagination',
        clickable: true,
        type:self.paginationType?self.paginationType:'bullets'
      },
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev'
      },
    });
  }
}
</script>

<style scoped>
@import url("../styles/swiperBullet.css");
/* 轮播图 */
.swiperBox{
  width:100%;
}
.swiper_Box{
  position: relative;
  overflow: hidden;
}
.swiper_Box .bannerItem img{
  height:auto;
  width:100%;
}
.swiperBox .bannerItem{
  width:100%;
  text-align: center;
}
.swiperBox .bannerItem img{
  height:auto;
  width:100%;
}
.swiper-pagination{
  position: absolute;
  bottom:20px;
  left:50%;
  transform: translateX(-50%);
}

</style>

swiper的引入形式是link标签引入样式

script标签引入js

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。

推荐阅读:
  1. vue如何封装swiper代码
  2. Swiper怎么在Vue中使用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue swiper ue

上一篇:创建SpringBoot工程并集成Mybatis的方法

下一篇:详解Linux安装教程

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》