Skip to content
API 风格:

IndexBar 索引栏 ​

通讯录式索引栏:右侧字母索引 + 分组锚点定位。scroll-spy 激活换算 (resolveActiveIndex)与触摸换算(hitIndexBar)全部消费 @lh-ui/share/core/index-bar 纯逻辑;本端为 DOM 测量 + scrollTo 胶水。

基础用法 ​

索引栏(点击 / 触摸定位分组)

当前索引:

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锚点分组头吸顶booleantrue
sticky-offset-top吸顶偏移 px(导航栏占位用)number0
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禁用(降低对比度)booleanfalse

IndexBarItem Slots ​

名称说明
default条目内容