在nuxt中使用swiper无法引入module

项目需要用到swiper

类似这种结构

在用swiper和slide标签组件的时候没有问题

就是没有左右切换和分页器,就是引入模块的问题

在swiper给出的vue代码模板中引入了 

// Import Swiper Vue.js components
import { Swiper, SwiperSlide } from "swiper/vue";

// Import Swiper styles
import "swiper/css";

import "swiper/css/pagination";
import "swiper/css/navigation";

import "./style.css";

在我的nuxt项目中复制上述代码,报错:找不到模块

解决方法:

对于左右切换的按钮,自己写样式如下


        <div
          class="swiper-pagination absolute w-100px bottom-10% flex justify-around align-center"
        >
          <span
            class="iconfont icon-arrow-left-filling"
            :class="disableLeft ? 'icon-arrow-left-filling-disable' : ''"
            @click="turnLeft"
            //点击左边就触发turnLeft函数
          ></span
          >{{ kvIndex + 1 }}/{{ list.length }}
          <span
            class="iconfont icon-arrow-right-filling"
            :class="disable ? 'icon-arrow-right-filling-disable' : ''"
            @click="turnRight"
          ></span>
        </div>

turnLeft函数:

    turnLeft() {
      const swiper = this.$refs.swiper.$swiper;
      console.log("swiper", swiper);
      swiper.slidePrev();
      if (this.kvIndex == 0) {
        this.disableLeft = true;
        this.disable = false;
      }
    },

其实就是调用了swiper的slidePrev方法。

=======================================================

还可以拿到当前页面是第几页:

ref绑定的是swiper标签

    slideChange() {
      this.kvIndex = this.$refs.swiper.$swiper.realIndex;
      console.log("this.kvIndex", this.kvIndex);
    },

跳转到指定的页面

 selectIndicator(index) {
      this.kvIndex = index;
      this.$refs.swiper.$swiper.slideTo(index);
    },

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值