IndexBar 索引欄
通訊錄式索引欄:右側字母索引 + 分組錨點定位。scroll-spy 激活換算 (resolveActiveIndex)與觸控換算(hitIndexBar)全部消費 @lh-ui/share/core/index-bar 純邏輯;本端為 DOM 測量 + scrollTo 膠水。
基礎用法
索引欄(點擊 / 觸控定位分組)
A
阿白
阿黄
B
柏舟
薄荷
C
春日
椿
A
B
C
當前索引:
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhIndexBar, LhIndexBarGroup, LhIndexBarItem } from '@lh-ui/vue3'
const current = ref('')
const groups: Record<string, string[]> = {
A: ['阿白', '阿黄'],
B: ['柏舟', '薄荷'],
C: ['春日', '椿'],
}
function onSelect(index: string) {
current.value = index
}
</script>
<template>
<LhIndexBar :index-list="['A', 'B', 'C']" @select="onSelect">
<LhIndexBarGroup v-for="key in ['A', 'B', 'C']" :key="key" :index="key">
<LhIndexBarItem v-for="name in groups[key]" :key="name">{{ name }}</LhIndexBarItem>
</LhIndexBarGroup>
</LhIndexBar>
</template>吸頂與自訂高亮
sticky 開啟分組頭吸頂(預設開),sticky-offset-top 為導覽列佔位移, highlight-color 自訂啟用索引高亮色。
吸頂 + 自訂高亮色
甲
甲一
乙
乙一
丙
丙一
甲
乙
丙
API
IndexBar Props
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| index-list | 索引項陣列(未傳預設 A-Z 26 項;空陣列算繪無側欄) | string[] | A-Z |
| sticky | 錨點分組頭吸頂 | boolean | true |
| sticky-offset-top | 吸頂偏移 px(導覽列佔位用) | number | 0 |
| highlight-color | 啟用索引高亮色(未傳取 indexBar.highlightColor 令牌) | string | — |
IndexBar Events
| 事件 | 說明 | 回呼參數 |
|---|---|---|
| select | 點擊 / 觸控側欄索引項 | index: string |
IndexBar Slots
| 名稱 | 說明 | 載荷 |
|---|---|---|
| default | 分組內容(LhIndexBarGroup / LhIndexBarItem 對) | — |
| item | 自訂索引項算繪 | { index } |
IndexBarGroup Props
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| index | 分組索引鍵(與 indexList 項對齊) | string | — |
IndexBarItem Props
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| disabled | 停用(降低對比度) | boolean | false |
IndexBarItem Slots
| 名稱 | 說明 |
|---|---|
| default | 條目內容 |

