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

