Skip to content

Navbar Custom Navigation Bar Component

This component is generally used in special cases where a custom navigation bar is required. It is generally recommended to use the navigation bar that comes with uni-app.

📌 Platform Differences

APP(vue)H5WeChat Mini ProgramAlipay Mini Program

🏯 Basic Usage Example

html
<!-- 全局使用 -->
<hy-navbar title="个人中心"></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="个人中心" placeholder></hy-navbar>
</template>

Background Color

html
<template>
    <hy-navbar title="个人中心" bgColor="#001f3f"></hy-navbar>
</template>

Fixed at Top

  • By configuring field, the navigation bar is fixed at the top
html
<template>
    <hy-navbar title="个人中心" 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="文档"
        :leftIcon="IconConfig.LEFT"
        leftText="返回"
        rightText="地址"
        :rightIcon="IconConfig.MAP"
    ></hy-navbar>
</template>

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

Custom Left Slot

html
<template>
    <hy-navbar title="自定义插槽" :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

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
leftTextPrompt text on the leftstring-
rightTextPrompt 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; content that overflows will be hidden with an ellipsis, unit: rpxstring|number400rpx
heightNavigation bar height (does not include the status bar height, which is automatically added internally); default unit for numeric values: pxstring|number44px
leftIconSizeSize of the left back icon; default unit for numeric values: pxstring|number20
leftIconColorColor of the left back iconstring-
autoBackWhether to automatically go 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 Values
leftCustom content for the left section-
rightCustom content for the right section-
centerCustom content for the center section-
03:29