UniApp 内置组件:`<swiper>` 详解

在 UniApp 中,<swiper> 是用于实现轮播图效果的内置组件。本篇文章将详细介绍 <swiper> 组件的使用方法,API 和属性。

简介

<swiper> 组件提供了一种方便的方式来实现内容的轮播展示。

示例

html 复制代码
<swiper :indicator-dots="true" :autoplay="true">
  <swiper-item v-for="(item, index) in images" :key="index">
    <image :src="item" />
  </swiper-item>
</swiper>

属性

基础属性

  • indicator-dots: 是否显示面板指示点,默认为 false
  • indicator-color: 指示点颜色,默认为 rgba(0, 0, 0, .3)
  • indicator-active-color: 当前选中的指示点颜色,默认为 #000000
  • autoplay: 是否自动切换,默认为 false

高级属性

  • current: 当前所在滑块的 index。
  • interval: 自动切换时间间隔,默认为 5000(单位 ms)。
  • duration: 滑动动画时长,默认为 500(单位 ms)。
  • circular: 是否采用衔接滑动,默认为 false
  • vertical: 滑动方向是否为纵向,默认为 false

事件

  • change: current 改变时会触发 change 事件,event.detail = {current, source}。
  • transition: swiper-item 的位置发生改变时会触发 transition 事件。
  • animationfinish: 动画结束时会触发 animationfinish 事件。

注意事项

  • <swiper> 组件内只应该放置 <swiper-item> 组件,否则会导致未定义的行为。

参考链接

在这篇文章中,我们详细介绍了 UniApp 的 <swiper> 组件,包括了各种属性和事件。希望能帮助您更有效地使用这个组件。

更多 UniApp 内置组件的详解,敬请期待。

相关推荐
前端开发爱好者18 分钟前
VSCode 重磅更新!要收费了?
前端·javascript·visual studio code
烛阴19 分钟前
C# 正则表达式(4):分支与回溯引用
前端·正则表达式·c#
曹牧1 小时前
Java:Assert.isTrue()
java·前端·数据库
脾气有点小暴1 小时前
uniapp自定义头部导航
前端·uni-app
假装我不帅2 小时前
jquery.nicescroll使用
前端·javascript·jquery
安_2 小时前
js 数组splice跟slice
开发语言·前端·javascript
用泥种荷花2 小时前
【LangChain学习笔记】链式调用
前端
yinuo2 小时前
IndexedDB 使用指南
前端
小徐_23332 小时前
2025,AI 编程元年,我用 TRAE 做了这些!
前端·程序员·trae
沛沛老爹3 小时前
Web开发者实战RAG评估:从指标到工程化验证体系
前端·人工智能·llm·agent·rag·评估