# 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="索引栏"。

最后更新: 2026/12/4 00:49:57

Copyright © 2024-2026 风默文学 | 宁ICP备2024006574号 | 公安备案徽标苏公网安备32040002010537