vue-awesome-swiper使用

vue-awesome-swiper使用

引入使用

import VueAwesomeSwiper from 'vue-awesome-swiper'
Vue.use(VueAwesomeSwiper)

具体代码


<swiper class="swiper" :options="swiperOption" ref="mySwiper">
      <swiper-slide
        class="swiper-slide"
        v-for="(item, index) in imgLists"
        :key="index" 
      >
        <img class="swiper-image" @mouseover="stopPlay" @mouseout="play" :src="item.url" alt />
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
      <div class="swiper-button-prev swiper-button-white" slot="button-prev"></div>
      <div class="swiper-button-next swiper-button-white" slot="button-next"></div>
</swiper>
<script>
export default {
  name: "HomeSwiper",
  // 子组件的data必须是个函数
  data() {
    return {
      imgLists: [{
          id:'1001',
          url:request("你的图片地址")
        },{
          id:'1002',
          url:request("你的图片地址")
        },{
          id:'1003',
          url:request("你的图片地址")
        }],
      swiperOption: {
        notNextTick: true, //循环
        autoplay: {
          delay: 6000, // 自动播放设置时间
          disableOnInteraction: false // 手动切换之后继续自动轮播
        },
        loop: true, // 循环
        directionType: "horizontal", // 方向
        pagination: {
          // 分页器
          el: ".swiper-pagination",
          clickable: true // 允许点击小圆点跳转
        },
        //点击下箭头
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev',
        }
      }
    };
  },
  computed: {
    mySwiper() {
      return this.$refs.mySwiper.swiper;
    }
  },
  methods: {
    stopPlay() {
      this.mySwiper.autoplay.stop(); // 当手指触摸时停止自动播放
    },
    play() {
      this.mySwiper.autoplay.start(); // 当手指离开时开始自动播放
    }
  }
};
</script>


图片不要设置z-index:-999 css标签,不然点击无效

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值