初用vue-awesome-swiper,通过官网步骤下载插件,
在这里插入图片描述
正常设置轮播图,但是卡在了一个小bug上,左右点击按钮无效,查询资料不断调试,最后发现原来是swiper版本的坑,官网直接下载的是最新版本swiper6,但是网上关于左右点击按钮的代码都是旧版本,不匹配,so,贴一下解决代码以供参考。

<template>
  <swiper ref="mySwiper" :options="swiperOption">
    <swiper-slide v-for="(item,index) in linkList" :key="index">
      <img :src="item.linklogo" class="linklogo" />
      <div class="linktip">{{item.name}}</div>
    </swiper-slide>
    <div class="swiper-button-prev" slot="button-prev" @click="next"></div>
    <div class="swiper-button-next" slot="button-next" @click="prev"></div>
  </swiper>
</template>
export default {
  data() {
    return {
      linkList: [
       
      ],
      swiperOption: {
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev"
        },
        slidesPerView: 6,
        spaceBetween: 0,
        freeMode: false
      }
    };
  },
  computed:{
    swiper() {
      return this.$refs.mySwiper.$swiper
    }
  },
  methods: {
    prev() {
      this.swiper.slidePrev();
    },
    next() {
      this.swiper.slideNext();
    }
  }
};
Logo

前往低代码交流专区

更多推荐