Skip to content

Navbar Custom Navigation Bar Component ​

This component is generally used in special cases where a custom navigation bar is needed. In general, it is recommended to use the navigation bar that comes with uni-app.

📌 Platform Compatibility ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

🏯 Basic Usage Example ​

html
<!-- Global usage -->
<hy-navbar title="Personal Center"></hy-navbar>

Preventing Collapse ​

  • By configuring placeholder, an element of equal height is generated when fixed at the top, to prevent collapse
html
<template>
    <hy-navbar title="Personal Center" placeholder></hy-navbar>
</template>

Background Color ​

html
<template>
    <hy-navbar title="Personal Center" bgColor="#001f3f"></hy-navbar>
</template>

Fixed at Top ​

  • By configuring fixed, the navigation bar is fixed at the top
html
<template>
    <hy-navbar title="Personal Center" fixed></hy-navbar>
</template>

Basic Usage Example ​

  • Use title to define the navigation bar title
  • Use leftIcon to define the left icon of the navigation bar
  • Use leftText to define the left text of the navigation bar
  • Use rightText to define the right text of the navigation bar
  • Use rightIcon to define the right icon of the navigation bar
html
<template>
    <hy-navbar
        title="Docs"
        :leftIcon="IconConfig.LEFT"
        leftText="Back"
        rightText="Address"
        :rightIcon="IconConfig.MAP"
    ></hy-navbar>
</template>

<script setup>
    import { IconConfig } from 'hy-app';
</script>

Custom Left Slot ​

html
<template>
    <hy-navbar title="Custom Slot" :fixed="false" bg-color="#F8F8F8">
        <template #left>
            <view class="u-nav-slot">
                <hy-icon :name="IconConfig.LEFT" size="16"></hy-icon>
                <hy-line direction="column" :hairline="false" length="16" margin="0 8px"></hy-line>
                <hy-icon name="home" size="15"></hy-icon>
            </view>
        </template>
    </hy-navbar>
</template>

<style lang="scss">
    .u-nav-slot {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        border-radius: 100px;
        border: 1rpx solid gainsboro;
        padding: 3px 7px;
        opacity: 0.8;
    }
</style>

API ​

Props ​

ParameterDescriptionTypeDefault
safeAreaInsetTopWhether to enable top safe area adaptationbooleantrue
placeholderWhen fixed at the top, whether to generate an element of equal height to prevent collapsebooleanfalse
fixedWhether the navigation bar is fixed at the topbooleantrue
borderWhether to display a bottom border at the bottom of the navigation barbooleanfalse
leftIconName of the left back iconstringIconConfig.LEFT
leftTextHint text on the leftstring-
rightTextHint text on the rightstring-
rightIconName of the right back iconstring-
titleNavigation bar title; if set to an empty string, the title placeholder area will be hiddenstring-
bgColorNavigation bar background settingstring-
titleWidthMaximum width of the navigation bar title; overflowing content is hidden with an ellipsis, unit rpxstring|number400rpx
heightNavigation bar height (does not include the status bar height, which is added automatically internally), default unit px for numbersstring|number44px
leftIconSizeSize of the left back icon, default unit px for numbersstring|number20
leftIconColorColor of the left back iconstring-
autoBackWhether to automatically navigate back to the previous page when the left area (back icon) is clickedbooleanfalse
titleStyleStyle of the title, in object or string formCSSProperties-
customStyleCustom external styles to be appliedCSSProperties-
customClassCustom external class namestring-

Events ​

Event NameDescriptionCallback Parameters
leftClickLeft area clicked-
rightClickRight area clicked-

Slots ​

Slot NameDescriptionAccepted Value
leftCustom left section content-
rightCustom right section content-
centerCustom center content-

CSS Variables ​

VariableDescriptionDefault
--hy-navbar-z-indexStacking level9999
--hy-navbar-heightHeight44px
--hy-navbar-text-font-sizeFont size of left/right text15px
--hy-navbar-title-font-sizeFont size of the center titleFollows --hy-font-size-base (28rpx)
--hy-navbar-sub-font-sizeFont size of the center subtitleFollows --hy-font-size-sm (24rpx)
--hy-navbar-sub-colorColor of the center subtitleFollows --hy-text-color--grey
12:33
battery