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 | 条目内容 |

