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條目內容