Swiper 轮播图 组件

介绍

常用于一组图片或卡片轮播,当内容空间不足时,可以用走马灯的形式进行收纳,进行轮播展现。

安装

  1. import { createApp } from 'vue';
  2. import { Swiper } from '@nutui/nutui';
  3. const app = createApp();
  4. app.use(Swiper);

代码演示

基础用法

auto-play 自动轮播的时长 init-page 初始索引值 pagination-visible 是否显示分页指示器 pagination-color 指示器颜色自定义

  1. <nut-swiper :init-page="state.page" :pagination-visible="true" pagination-color="#426543" auto-play="3000">
  2. <nut-swiper-item>
  3. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/152158/32/19170/280589/6035429fE08208901/024578cf04ce3b47.jpg!cr_1125x445_0_171" alt="" />
  4. </nut-swiper-item>
  5. <nut-swiper-item>
  6. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/159602/22/7999/126515/6035f371E6f95bfee/559cb1ee48c962c9.jpg" alt="" />
  7. </nut-swiper-item>
  8. <nut-swiper-item>
  9. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/166846/13/7534/136440/60338b5cEd491d8b3/9e5527429136ab86.jpg" alt="" />
  10. </nut-swiper-item>
  11. <nut-swiper-item>
  12. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/145433/27/14059/141680/5facf066Ec402354c/530d5a316aed55fc.jpg!cr_1125x445_0_171" alt="" />
  13. </nut-swiper-item>
  14. </nut-swiper>

自定义大小

width 自定义轮播大小

  1. <nut-swiper :init-page="state.page2" :loop="false" width="300">
  2. <nut-swiper-item>
  3. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/152158/32/19170/280589/6035429fE08208901/024578cf04ce3b47.jpg!cr_1125x445_0_171" alt="" />
  4. </nut-swiper-item>
  5. <nut-swiper-item>
  6. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/159602/22/7999/126515/6035f371E6f95bfee/559cb1ee48c962c9.jpg" alt="" />
  7. </nut-swiper-item>
  8. <nut-swiper-item>
  9. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/166846/13/7534/136440/60338b5cEd491d8b3/9e5527429136ab86.jpg" alt="" />
  10. </nut-swiper-item>
  11. <nut-swiper-item>
  12. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/145433/27/14059/141680/5facf066Ec402354c/530d5a316aed55fc.jpg!cr_1125x445_0_171" alt="" />
  13. </nut-swiper-item>
  14. </nut-swiper>

自定义分页指示器

v-slot:page 表示自定义指示器

  1. <nut-swiper :init-page="state.page3" :loop="true" @change="change">
  2. <nut-swiper-item>
  3. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/152158/32/19170/280589/6035429fE08208901/024578cf04ce3b47.jpg!cr_1125x445_0_171" alt="" />
  4. </nut-swiper-item>
  5. <nut-swiper-item>
  6. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/159602/22/7999/126515/6035f371E6f95bfee/559cb1ee48c962c9.jpg" alt="" />
  7. </nut-swiper-item>
  8. <nut-swiper-item>
  9. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/166846/13/7534/136440/60338b5cEd491d8b3/9e5527429136ab86.jpg" alt="" />
  10. </nut-swiper-item>
  11. <nut-swiper-item>
  12. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/145433/27/14059/141680/5facf066Ec402354c/530d5a316aed55fc.jpg!cr_1125x445_0_171" alt="" />
  13. </nut-swiper-item>
  14. <template v-slot:page>
  15. <div class="page"></div>
  16. </template>
  17. </nut-swiper>

垂直方向

direction 自定义轮播方向

  1. <nut-swiper :init-page="state.page4" :loop="true" auto-play="3000" direction="vertical" height="150" :pagination-visible="true" style="height: 150px">
  2. <nut-swiper-item>
  3. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/152158/32/19170/280589/6035429fE08208901/024578cf04ce3b47.jpg!cr_1125x445_0_171" alt="" />
  4. </nut-swiper-item>
  5. <nut-swiper-item>
  6. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/159602/22/7999/126515/6035f371E6f95bfee/559cb1ee48c962c9.jpg" alt="" />
  7. </nut-swiper-item>
  8. <nut-swiper-item>
  9. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/166846/13/7534/136440/60338b5cEd491d8b3/9e5527429136ab86.jpg" alt="" />
  10. </nut-swiper-item>
  11. <nut-swiper-item>
  12. <img src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/145433/27/14059/141680/5facf066Ec402354c/530d5a316aed55fc.jpg!cr_1125x445_0_171" alt="" />
  13. </nut-swiper-item>
  14. </nut-swiper>

API

Props

参数说明类型默认值
width轮播卡片的宽度Number、Stringwindow.innerWidth
height轮播卡片的高度String、Number0
direction轮播方向,可选值horizontal,verticalString‘horizontal’
pagination-visible分页指示器是否展示Booleanfalse
pagination-color分页指示器选中的颜色String‘#fff’
loop是否循环轮播Booleantrue
duration动画时长(单位是ms)Number、String500
auto-play自动轮播时长,0表示不会自动轮播Number、String0
init-page初始化索引值Number、String0
touchable是否可触摸滑动Booleantrue
is-preventDefault滑动过程中是否禁用默认事件Booleantrue
is-stopPropagation滑动过程中是否禁止冒泡Booleantrue

Events

事件名说明回调参数
change滑动之后的回调当前索引值index

API

事件名说明参数
prev切换到上一页-
next切换到下一页-
to切换到指定轮播index:number

Swiper  轮播 - 图1