import{o as a,a as t,y as n}from"./vue-libs.b44bc779.js";const e={class:"van-doc-markdown-body"},l=n(`

IndexBar

Intro

Used for indexed sorting display and quick positioning of lists.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

import { createApp } from 'vue';
import { IndexBar } from 'vant';

const app = createApp();
app.use(IndexBar);
app.use(IndexAnchor);

Usage

Basic Usage

<van-index-bar>
  <van-index-anchor index="A" />
  <van-cell title="Text" />
  <van-cell title="Text" />
  <van-cell title="Text" />

  <van-index-anchor index="B" />
  <van-cell title="Text" />
  <van-cell title="Text" />
  <van-cell title="Text" />

  ...
</van-index-bar>

Custom Index List

<van-index-bar :index-list="indexList">
  <van-index-anchor index="1">Title 1</van-index-anchor>
  <van-cell title="Text" />
  <van-cell title="Text" />
  <van-cell title="Text" />

  <van-index-anchor index="2">Title 2</van-index-anchor>
  <van-cell title="Text" />
  <van-cell title="Text" />
  <van-cell title="Text" />

  ...
</van-index-bar>
export default {
  setup() {
    return {
      indexList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    };
  },
};

API

IndexBar Props

AttributeDescriptionTypeDefault
index-listIndex Liststring[] | number[]A-Z
z-indexz-indexnumber | string1
stickyWhether to enable anchor sticky topbooleantrue
sticky-offset-topAnchor offset top when stickynumber0
highlight-colorIndex character highlight colorstring#ee0a24
teleport v3.0.19Specifies a target element where IndexBar will be mountedstring | Element-

IndexAnchor Props

AttributeDescriptionTypeDefault
indexIndexnumber | string-

IndexBar Events

EventDescriptionArguments
selectEmitted when an index is selectedindex: number | string
changeEmitted when active index changedindex: number | string

IndexBar Methods

Use ref to get IndexBar instance and call instance methods.

NameDescriptionAttributeReturn value
scrollToscroll to target elementindex: number | string-

Types

The component exports the following type definitions:

import type { IndexBarProps, IndexAnchorProps, IndexBarInstance } from 'vant';

IndexBarInstance is the type of component instance:

import { ref } from 'vue';
import type { IndexBarInstance } from 'vant';

const indexBarRef = ref<IndexBarInstance>();

indexBarRef.value?.scrollTo('B');

IndexAnchor Slots

NameDescription
defaultAnchor content, show index by default

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-index-bar-sidebar-z-index2-
--van-index-bar-index-font-sizevar(--van-font-size-xs)-
--van-index-bar-index-line-heightvar(--van-line-height-xs)-
--van-index-bar-index-active-colorvar(--van-danger-color)-
--van-index-anchor-z-index1-
--van-index-anchor-padding0 var(--van-padding-md)-
--van-index-anchor-text-colorvar(--van-text-color)-
--van-index-anchor-font-weightvar(--van-font-weight-bold)-
--van-index-anchor-font-sizevar(--van-font-size-md)-
--van-index-anchor-line-height32px-
--van-index-anchor-background-colortransparent-
--van-index-anchor-sticky-text-colorvar(--van-danger-color)-
--van-index-anchor-sticky-background-colorvar(--van-background-color-light)-
`,15),d=[l],i={__name:"README",setup(p,{expose:s}){return s({frontmatter:{}}),(c,h)=>(a(),t("div",e,d))}};export{i as default};