vue3 使用swiper

​在 vue3 中使用 swiper, 实现轮播图的效果;如果组件样式等模块引入不当,很有可能导致,页面无效果;或者想要的箭头或者切换效果异常问题。具体使用方式如下所示:
 

1.安装 swiper插件

npm install swiper //目前版本10.2.0

2.组件方式使用

<template>
  <swiper
    modules
    navigation
    :pagination="{ clickable: true }"
    :scrollbar="{ draggable: true }"
    @swiper="onSwiper"
    @slideChange="onSlideChange"
  >
   <swiper-slide v-for="(item, index) in imgList" :key="index">
       <el-image :src="item.url" fit="contain"></el-image>
   </swiper-slide>    
  </swiper>
</template>
<script>
  // 这里需要什么其他功能可以查询文档
  import { Navigation, Pagination, A11y } from 'swiper/modules'
  import { Swiper, SwiperSlide } from 'swiper/vue'

  // 导入插件样式
  import 'swiper/css'
  import 'swiper/css/navigation' // 左右按钮
  import 'swiper/css/pagination' // 分页小圆点

  export default {
    components: {
      Swiper,
      SwiperSlide,
    },
    setup() {
      const onSwiper = (swiper) => {
        console.log(swiper);
      };
      const onSlideChange = () => {
        console.log('slide change');
      };
      return {
        onSwiper,
        onSlideChange,
        modules: [Navigation, Pagination, A11y],
      };
    },
  };
</script>

3.最终效果

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值