For AI agents: the complete documentation index is available at /apps-plugin/docs/llms.txt, the full documentation bundle is available at /apps-plugin/docs/llms-full.txt, and this page is available as Markdown at /apps-plugin/docs/components/view-container/swiper.md.

swiper

轮播容器组件,支持自动播放、循环、自定义动画等功能。子节点须为 SwiperItem 组件。

扫码预览

扫码预览 swiper

Props

属性名类型默认值必填说明
autoPlaybooleanfalse否是否启用自动播放
autoPlayIntervalnumber2000否自动播放间隔
blockNativeEventbooleanfalse否是否阻止原生事件
bounceConfigBounceConfig-否回弹参数配置
children(prop: RenderFunctionProps<T>) => ReactElement-是子元素,应该是一个函数,返回 SwiperItem
classNamestring-否组件类名
consumeSlideEvent[number, number][][[-180, -135], [-45, 45], [135, 180]]否决定 Swiper 如何响应不同角度的触摸
containerWidthnumberscreenWidth否容器宽度
dataT[]-是轮播图数据集合
durationnumber500否翻页或滑动动画的持续时间
initialIndexnumber0否初始索引,仅在首屏时使用,后续更新将被忽略
itemHeightnumber | "auto"-否轮播项高度
itemWidthnumber-是轮播项宽度
loopbooleanfalse否是否开启循环轮播
loopDuplicateCountnumber2否当 loop 为 true 时,Swiper 会复制前 2 个和后 2 个项目来创建循环效果。
此属性可用于自定义复制第一个和最后一个项目的数量
main-thread:customAnimation(value: number, index: number) => CSSProperties-否自定义动画效果,应该是一个主线程函数
main-thread:easing(progress: number) => number-否自定义翻页效果的缓动函数
main-thread:onOffsetChange(offset: number) => void-否Swiper 偏移量改变时的回调函数,应该是一个主线程函数
mode"normal" | "custom"normal否Swiper 的模式。普通模式会使 SwiperItem 依次排列。
自定义模式会使 SwiperItem 以绝对定位方式放置在最左侧
modeConfig{ align?: "center" | "end" | "start"; spaceBetween?: number } | Record<string, unknown>-否模式的额外配置
offsetLimit[number, number]-否用于限制或扩展 Swiper 的偏移量范围,可用于限制偏移量以避免过度滚动
onChange(current: number) => void-否当前索引改变时的回调函数
onSwipeStart(current: number) => void-否开始滑动时的回调函数,可与 onSwipeStop 配合使用,用于在滑动时禁用点击事件
onSwipeStop(current: number) => void-否停止滑动时的回调函数,可与 onSwipeStart 配合使用
RTLboolean | "lynx-rtl"false否是否启用 RTL 模式
styleCSSProperties-否根元素样式,控制包含轮播图的可见视口/框架

Ref 方法

方法名类型说明
cancelAnimation() => void取消当前正在运行的动画。谨慎使用,可能会破坏内部状态
swipeNext() => void滑动到下一个项目
swipePrev() => void滑动到上一个项目
swipeTo(index: number, options?: SwipeToOptions) => void滑动到指定索引的项目