# IndexBar 索引欄
通訊錄式索引欄:右側字母索引 + 分組錨點定位。scroll-spy 啟用換算
(resolveActiveIndex)與觸控換算(hitIndexBar)全部消費
@lh-ui/share/core/index-bar 純邏輯;本端為 DOM 測量 + scrollTo 膠水。
索引欄(點選 / 觸控定位分組)
<template>
<div class="demo-col" style="gap: 18px">
<div class="index-demo-scroll">
<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>
</div>
<p class="demo-note">當前索引:{{ current }}</p>
</div>
</template>
<script>
export default {
data: () => ({
current: '',
groups: {
A: ['阿白', '阿黃'],
B: ['柏舟', '薄荷'],
C: ['春日', '椿'],
},
}),
methods: {
onSelect(index) {
this.current = index
},
},
}
</script>
# 吸頂與自訂高亮
sticky 開啟分組頭吸頂(預設開),sticky-offset-top 為導覽列佔位偏移,
highlight-color 自訂啟用索引高亮色。
<LhIndexBar :index-list="['甲', '乙', '丙']" :sticky-offset-top="0" highlight-color="#c0392b">
<LhIndexBarGroup index="甲"><LhIndexBarItem>甲一</LhIndexBarItem></LhIndexBarGroup>
<LhIndexBarGroup index="乙"><LhIndexBarItem>乙一</LhIndexBarItem></LhIndexBarGroup>
<LhIndexBarGroup index="丙"><LhIndexBarItem>丙一</LhIndexBarItem></LhIndexBarGroup>
</LhIndexBar>
# Props
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| indexList | 索引項陣列(未傳預設 A-Z 26 項;空陣列渲染無側欄) | string[] | A-Z |
| sticky | 錨點分組頭吸頂 | boolean | true |
| stickyOffsetTop | 吸頂偏移 px(導覽列佔位用) | number | 0 |
| highlightColor | 啟用索引高亮色(未傳取 indexBar.highlightColor 令牌) | string | — |
| sx | sx 快速版面配置屬性 | LhSxProps | — |
# Events
| 事件 | 說明 | 載荷 |
|---|---|---|
| select | 點選 / 觸控側欄索引項 | index: string |
# Slots
| 名稱 | 說明 | 載荷 |
|---|---|---|
| default | 分組內容(LhIndexBarGroup / LhIndexBarItem 對) | — |
| item | 自訂索引項渲染 | { index } |
# LhIndexBarGroup Props
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| index | 分組索引鍵(與 indexList 項對齊,必填) | string | — |
| sx | sx 快速版面配置屬性 | LhSxProps | — |
# LhIndexBarItem Props
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| disabled | 停用(降低對比度) | boolean | false |
| sx | sx 快速版面配置屬性 | LhSxProps | — |
# 無障礙
根元素 role="navigation" + aria-label="索引欄"。
Copyright © 2024-2026 风默文学 | 宁ICP备2024006574号 |
苏公网安备32040002010537