Skip to content

IndexBar - Vant 4

IndexBar

🚀 Transform your long lists into navigable masterpieces! The IndexBar component brings alphabetical organization and lightning-fast positioning to your mobile interfaces.

📖 Intro

Create intuitive, indexed navigation for large datasets with smooth scrolling and sticky positioning. Perfect for contact lists, directories, and any content that benefits from alphabetical organization.

📦 Install

Get started with IndexBar by registering both IndexBar and IndexAnchor components globally. Refer to Component Registration for more registration ways.

js
import { createApp } from'vue'; import { IndexBar } from'vant'; const app = createApp(); app.use(IndexBar); app.use(IndexAnchor);

🎨 Usage

🌟 Basic Usage

Create a smooth, alphabetical navigation experience with automatic index generation:

html

🎯 Custom Index List

Customize your navigation with numeric indices or any custom sequence that fits your data structure:

html
js
exportdefault { setup() { return { indexList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], }; }, };

🔧 API

🎛️ IndexBar Props

Configure your IndexBar with these comprehensive options:

AttributeDescriptionTypeDefault
index-listIndex List*(stringnumber)[]*
z-indexz-index*numberstring*
stickyWhether to enable anchor sticky topbooleantrue
sticky-offset-topAnchor offset top when stickynumber0
highlight-colorIndex character highlight colorstring#1989fa

| teleport | Specifies a target element where IndexBar will be mounted | string | Element | - |

🎯 IndexAnchor Props

Define anchor points for your indexed content:

AttributeDescriptionTypeDefault
indexIndex*numberstring*

📡 IndexBar Events

Stay connected with user interactions and navigation changes:

EventDescriptionArguments
selectEmitted when an index is selected*index: number
changeEmitted when active index changed*index: number

⚙️ IndexBar Methods

Programmatically control navigation with these powerful methods. Use ref to get IndexBar instance and call instance methods.

NameDescriptionAttributeReturn value
scrollToscroll to target element*index: numberstring*

📝 Types

The component exports comprehensive type definitions for enhanced TypeScript development:

ts
importtype { IndexBarProps, IndexAnchorProps, IndexBarInstance } from'vant';

IndexBarInstance is the type of component instance:

ts
import { ref } from'vue'; importtype { IndexBarInstance } from'vant'; const indexBarRef = ref<IndexBarInstance>(); indexBarRef.value?.scrollTo('B');

🎰 IndexAnchor Slots

Customize anchor content with flexible slot options:

NameDescription
defaultAnchor content, show index by default

🎨 Theming

🎯 CSS Variables

Transform your IndexBar's appearance with these comprehensive styling variables. Refer to ConfigProvider component for global theming options.

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-primary-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-bold)-
--van-index-anchor-font-sizevar(--van-font-size-md)-
--van-index-anchor-line-height32px-
--van-index-anchor-backgroundtransparent-
--van-index-anchor-sticky-text-colorvar(--van-primary-color)-
--van-index-anchor-sticky-backgroundvar(--van-background-2)-
  • List - List component for displaying indexed content
  • Cell - Cell component for list items
  • Sticky - Sticky positioning component
  • Search - Search component for filtering lists
  • Sidebar - Sidebar navigation component
  • Tab - Tab navigation component
  • ConfigProvider - Global configuration
  • Lazyload - Lazy loading for large lists

Enterprise-level mobile solution based on Vant