Carousel 轮播
横向轮播:原生 swiper 封装(不手写手势),自动轮播、循环回绕、dots 指示器 (bottom 文档流 / overlay 叠加)自绘。页序数学全部消费 @lh-ui/share/core/carousel。
平台差异(登记):小程序运行时拿不到插槽子节点清单,页内容一律走 items 数据驱动 + item 作用域插槽(web 三端的「默认插槽多子」形态在本端不适用);
showArrow是 web 桌面端形态,本端不渲染。
基础用法
vue
<template>
<lh-carousel :items="banners" :height="140">
<template #item="{ index, item }">
<view class="page">{{ item }}({{ index + 1 }})</view>
</template>
</lh-carousel>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const banners = ['水墨', '丹青', '工笔']
</script>自动轮播与非循环
vue
<template>
<lh-carousel :items="banners" :height="140" :autoplay="3000" :loop="false">
<template #item="{ item }">
<view class="page">{{ item }}</view>
</template>
</lh-carousel>
</template>受控 v-model
vue
<template>
<lh-carousel v-model="page" :items="banners" :height="140">
<template #item="{ item }">
<view class="page">{{ item }}</view>
</template>
</lh-carousel>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const page = ref(0)
</script>Props
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| v-model / modelValue | 当前页序号(受控;不传非受控自走) | number | — |
| items | 页数据源(每项一页,配合 item 插槽) | unknown[] | — |
| autoplay | 自动轮播间隔 ms(0 / 不传 = 不自动) | number | 0 |
| loop | 循环回绕(映射 swiper 的 circular) | boolean | true |
| indicator | 指示器形态 | "dots" | "none" | 'dots' |
| indicatorPosition | 指示器位置 | "bottom" | "overlay" | 'bottom' |
| height | 高度 px | number | 200 |
| showArrow | web 桌面端左右箭头(本端不渲染,仅保留契约位) | boolean | false |
| disabled | 禁用(灰化并停用自动轮播) | boolean | false |
| ariaLabel | 无障碍名称(未传取页码播报) | string | — |
| customClass | 自定义类名(透传根节点) | string | — |
| sx | sx 快速布局属性 | — | — |
Events
| 事件 | 说明 | 回调参数 |
|---|---|---|
| update:modelValue | 受控页序回写 | (value: number) |
| change | 页面切换(autoplay / 手指 / 编程 current 统一收口) | (value: number) |
Slots
| 名称 | 说明 |
|---|---|
| item | 分页内容作用域插槽 { index, item } |
方法(ref)
| 方法 | 说明 |
|---|---|
| prev() / next() | 上一页 / 下一页 |
| goTo(index) | 跳转到指定页 |
无障碍
- 根节点
role="region"+aria-roledescription="carousel",可达名称取ariaLabel或页码播报文案;非当前页aria-hidden

