vue3 中使用 swiper

139 篇文章 1 订阅
4 篇文章 0 订阅
本文档介绍了在Vue项目中遇到Swiper版本兼容问题的解决方案,包括安装特定版本的node-sass、sass-loader和swiper,并提供了Vue组件的使用示例。详细步骤包括运行指定版本的npm安装命令,以及在模板和脚本中引入Swiper组件和样式。通过这些步骤,可以成功解决Swiper在Vue项目中的兼容性问题并实现滑动效果。
摘要由CSDN通过智能技术生成

 

官方这个不大好用因为有版本兼容问题:

https://swiperjs.com/vue

可以参考如下方式:主要是版本兼容问题

即:

 npm install node-sass@4.14.1  -S

npm install sass-loader@7.3.1 -S

npm install swiper@6.7.0 -S

然后在vue中复制官方上的文档

即:

<template>
  <swiper
    :slides-per-view="3"
    :space-between="50"
    @swiper="onSwiper"
    @slideChange="onSlideChange"
  >
    <swiper-slide>Slide 1</swiper-slide>
    <swiper-slide>Slide 2</swiper-slide>
    <swiper-slide>Slide 3</swiper-slide>
    ...
  </swiper>
</template>
<script>
  // Import Swiper Vue.js components
  import { Swiper, SwiperSlide } from 'swiper/vue';

  // Import Swiper styles
  import 'swiper/swiper.scss';
  export default {
    components: {
      Swiper,
      SwiperSlide,
    },
    methods: {
      onSwiper(swiper) {
        console.log(swiper);
      },
      onSlideChange() {
        console.log('slide change');
      },
    },
  };
</script>

最终的效果如下:

更详细的使用请参考:

https://blog.csdn.net/jjw_zyfx/article/details/117884136?spm=1001.2014.3001.5501

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值