vue项目中 使用swiper轮播图

首先 安装 依赖

 npm install swiper --save-dev

使用的vue文件中 导入

import { Swiper, SwiperSlide } from "vue-awesome-swiper";
import "swiper/swiper-bundle.css";

挂载 调用

  components: {
    Swiper,
    SwiperSlide,
  },

书写 元素

   <swiper
          ref="swiper1"
          class="swiper1"
               swiperOption1 为swiper配置      
          :options="swiperOption1"
          @mouseover.native="enter1()"
          @mouseout.native="leave1()"
        >
          <swiper-slide v-for="(item, listIndex) in saleInfo" :key="listIndex">
            <div
              :class="{ active: selectIndex == listIndex }"
              @click="switchTab(listIndex)"
            >
              <p
                class="turnTitle curpoi text_align"
                :class="{ active: selectIndex == listIndex }"
              >
                {{ item.naviName }}
              </p>
              <p
                class="text_align"
                :class="{ active_border: selectIndex == listIndex }"
              ></p>
            </div>
          </swiper-slide>
          <div
            ref="left1"
            class="swiper-button-prev display_none "
            slot="button-prev"
            @click="prev1"
          ></div>
          <div
            ref="right1"
            class="swiper-button-next display_none"
            slot="button-next"
            @click="next1"
          ></div>
        </swiper>

初始化 swiper配置

  data() {
    return {
    
      swiperOption1: {
         一个窗口下 放几个 轮播图
        slidesPerView: 7,
        空隙
        spaceBetween: 10,
        slidesPerGroup: 7,

        loop: false,
        loopFillGroupWithBlank: true,
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
        },
        navigation: {
         左右的点击箭头
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },
        on: {
          resize: () => {
                       左右箭头的点击事件 点击 箭头 轮播翻页
            this.$refs.swiper1.$swiper.changeDirection(
              window.innerWidth <= 960 ? "vertical" : "horizontal"
            );
          },
        },
      },
    };
  },

左右箭头的methods 方法 

   prev1() {
      this.$refs.swiper1.$swiper.slidePrev();
    },
    next1() {
      this.$refs.swiper1.$swiper.slideNext();
    },

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值