Skip to content

NavBar - Vant 4

Install

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

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

Usage

Basic Usage

html

Back

html
js
exportdefault { setup() { constonClickLeft = () => history.back(); return { onClickLeft, }; }, };

Right Button

html
js
import { showToast } from'vant'; exportdefault { setup() { constonClickLeft = () => history.back(); constonClickRight = () => showToast('Button'); return { onClickLeft, onClickRight, }; }, };

Use Slot

html

Disable Button

Use the left-disabled or right-disabled props to disable the buttons on either side. The prop reduces the opacity of the button and makes it unclickable.

html

API

Props

AttributeDescriptionTypeDefault
titleTitlestring''
left-textLeft Textstring''
right-textRight Textstring''
left-disabled v4.6.8Whether to disable the left button, decrease opacity and make it unclickablebooleanfalse
right-disabled v4.6.8Whether to disable the right button, decrease opacity and make it unclickablebooleanfalse
left-arrowWhether to show left arrowbooleanfalse
borderWhether to show bottom borderbooleantrue
fixedWhether to fixed topbooleanfalse
placeholderWhether to generate a placeholder element when fixedbooleanfalse
z-indexZ-index*numberstring*
safe-area-inset-topWhether to enable top safe area adaptationbooleanfalse
clickableWhether to show click feedback when the left or right content is clickedbooleantrue

Slots

NameDescription
titleCustom title
leftCustom left side content
rightCustom right side content

Events

EventDescriptionArguments
click-leftEmitted when the left button is clickedevent: MouseEvent
click-rightEmitted when the right button is clickedevent: MouseEvent

Types

The component exports the following type definitions:

ts
importtype { NavBarProps } from'vant';

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-nav-bar-height46px-
--van-nav-bar-backgroundvar(--van-background-2)-
--van-nav-bar-arrow-size16px-
--van-nav-bar-icon-colorvar(--van-primary-color)-
--van-nav-bar-text-colorvar(--van-primary-color)-
--van-nav-bar-title-font-sizevar(--van-font-size-lg)-
--van-nav-bar-title-text-colorvar(--van-text-color)-
--van-nav-bar-z-index1-

Enterprise-level mobile solution based on Vant