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 内置组件的详解,敬请期待。

相关推荐
天宇&嘘月1 小时前
web第三次作业
前端·javascript·css
小王不会写code2 小时前
axios
前端·javascript·axios
发呆的薇薇°3 小时前
vue3 配置@根路径
前端·vue.js
luckyext3 小时前
HBuilderX中,VUE生成随机数字,vue调用随机数函数
前端·javascript·vue.js·微信小程序·小程序
小小码农(找工作版)3 小时前
JavaScript 前端面试 4(作用域链、this)
前端·javascript·面试
前端没钱4 小时前
前端需要学习 Docker 吗?
前端·学习·docker
前端郭德纲4 小时前
前端自动化部署的极简方案
运维·前端·自动化
海绵宝宝_4 小时前
【HarmonyOS NEXT】获取正式应用签名证书的签名信息
android·前端·华为·harmonyos·鸿蒙·鸿蒙应用开发
码农土豆5 小时前
chrome V3插件开发,调用 chrome.action.setIcon,提示路径找不到
前端·chrome
鱼樱前端5 小时前
深入JavaScript引擎与模块加载机制:从V8原理到模块化实战
前端·javascript