付珍的踩坑

vue-awesome-swiper 的左右箭头与swiper的on属性的点击事件冲突的解决方法

当点击左右箭头时,swiper轮播图应该出现切换效果,但同时也会触发图片上的跳转事件,隐藏我们只需要判断事件源点击的是不是左右箭头就行了。

<template>
  <swiper class="swiper" :options="swiperOption" >
    <swiper-slide v-for="item in banners" :key="item.id">
        <img :src="item.bg_image" alt="">
    </swiper-slide>
    <div class="swiper-pagination" slot="pagination"></div>
    <div class="swiper-button-prev" slot="button-prev"></div>
    <div class="swiper-button-next" slot="button-next"></div>
  </swiper>
</template>

<script>
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
var vm = null
export default {
  name: 'Banner',
  components: {
    Swiper,
    SwiperSlide
  },
  data () {
    return {
      swiperOption: {
        slidesPerView: 1,
        spaceBetween: 30,
        loop: true,
        autoplay: {
          stopOnLastSlide: true,
          disableOnInteraction: false
        },
        effect: 'fade',
        preventClicks: false,
        fadeEffect: {
          crossFade: true
        },
        pagination: {
          el: '.swiper-pagination',
          clickable: true
        },
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        },
        on: {
          click: function (e) {
            const index = this.realIndex
            if (e.target.className !== 'swiper-button-next' && e.target.className !== 'swiper-button-prev') {
              vm.handclick(index)
            }
          }
        }
      },
      banners: []
    }
  },
  methods: {
    handclick (index) {
      window.location.href = this.banners[index].slide_link
    }
  },
  created () {
    vm = this
  }
}
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值