Skip to content

This component is generally used in special cases, and it is not used when a custom navigation bar is required. It is generally recommended to use the navigation bar with uni-app.

platform compatibility

App(vue)App(nvue)H5小程序VUE2VUE3

Basic usage

By default, this component only has a left arrow, click to return to the previous page, if you don't want to use the left content, you can manually hide it by setting showLeft to false.

  • If you want to customize the word "return" on the right side of the return arrow, you can set left-text to "return"
  • Pass in the title to be displayed through the title parameter, set the width of the title area through title-width (rpx), if the text exceeds it, it will be hidden by an ellipsis
  • Configure whether to fix the navigation bar at the top via fixed

Description

  • In the applet, the navigation bar will reserve the capsule position on the right side of the navigation bar through the mpRightReserveCapsule (default is true) property, avoiding this area.
  • There is a border at the bottom of the component by default, if you don't need it, you can set the border to false
vue
<template>
	<view>
		<!-- Support autoBack, the default is false -->
        <wu-navbar
            title="personal center"
            @rightClick="rightClick"
            :autoBack="true"
        >
        </wu-navbar>
	</view>
</template>

<script>
    methods:{
        rightClick() {
            console.log('rightClick');
        },
        leftClick() {
            console.log('leftClick');
        }
    }
</script>
<template>
	<view>
		<!-- Support autoBack, the default is false -->
        <wu-navbar
            title="personal center"
            @rightClick="rightClick"
            :autoBack="true"
        >
        </wu-navbar>
	</view>
</template>

<script>
    methods:{
        rightClick() {
            console.log('rightClick');
        },
        leftClick() {
            console.log('leftClick');
        }
    }
</script>

Precautions

Since you want to customize the navigation bar, you must first cancel the navigation bar that comes with the system. You need to set it in "pages.json" in the root directory of the uni-app target, and set the color of the status bar font here (H5 is invalid) , After customizing the navigation bar, if you want to dynamically set the color-related parameters of the navigation bar through "uni.setNavigationBarColor", it may cause problems, please do not use this method.

js
// pages.json

"pages": [
	// navbar - custom navigation bar
	{
		"path": "/pages/navbar/index",
		"style": {
			"navigationStyle": "custom" ,// Hide system navigation bar
			"navigationBarTextStyle": "white" // The font of the status bar is white, and it can only be white-white or black-black.
		}
	}
]
// pages.json

"pages": [
	// navbar - custom navigation bar
	{
		"path": "/pages/navbar/index",
		"style": {
			"navigationStyle": "custom" ,// Hide system navigation bar
			"navigationBarTextStyle": "white" // The font of the status bar is white, and it can only be white-white or black-black.
		}
	}
]

The height of the navigation bar can be configured through height (unit px, default 44, consistent with the height of the uni-app system navigation bar), this height is the height of the content of the navigation bar, excluding the height of the status bar, inside the component The height of the status bar will be added automatically, and the occupied area of ​​the status bar will be filled.

Customize the content of the navigation bar

Content passed in by custom slot

vue
<template>
	<view>
        <wu-navbar
            leftText="return"
            title="personal center"
            :safeAreaInsetTop="false"
        >
            <template #left>
                <view class="wu-nav-slot">
                    <wu-icon
                        name="arrow-left"
                        size="19"
                    ></wu-icon>
                    <wu-line
                        direction="column"
                        :hairline="false"
                        length="16"
                        margin="0 8px"
                    ></wu-line>
                    <wu-icon
                        name="home"
                        size="20"
                    ></wu-icon>
                </view>
            </template>
        </wu-navbar>
	</view>
</template>
<template>
	<view>
        <wu-navbar
            leftText="return"
            title="personal center"
            :safeAreaInsetTop="false"
        >
            <template #left>
                <view class="wu-nav-slot">
                    <wu-icon
                        name="arrow-left"
                        size="19"
                    ></wu-icon>
                    <wu-line
                        direction="column"
                        :hairline="false"
                        length="16"
                        margin="0 8px"
                    ></wu-line>
                    <wu-icon
                        name="home"
                        size="20"
                    ></wu-icon>
                </view>
            </template>
        </wu-navbar>
	</view>
</template>

Customize the background color of the navigation bar

wu-ui provides a bgColor parameter to customize the background color of the navigation bar:

  • Gradient
  • transparent color
  • normal color
vue
<template>
	<view>
		<wu-navbar title="" :bgColor="bgColor"></wu-navbar>
		<view class="content">
			<!-- Text content -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgColor: 'linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))',
			}
		}
	}
</script>
<template>
	<view>
		<wu-navbar title="" :bgColor="bgColor"></wu-navbar>
		<view class="content">
			<!-- Text content -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgColor: 'linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))',
			}
		}
	}
</script>

API

property namedescriptiontypedefault valueoptional values ​​
safeAreaInsetTopWhether to enable top safe area adaptationBooleantruetrue / false
placeholderWhen pinned to the top, whether to generate an equal height element to prevent collapseBooleanfalsetrue / false
fixedWhether the navigation bar is fixed at the topBooleantruetrue / false
borderWhether to display a border at the bottom of the navigation barBooleanfalsetrue / false
showLeftWhether to show the leftBooleantruetrue / false
mpRightReserveCapsuleWhether to reserve a capsule position on the right side of the navigation bar of the appletBooleantruetrue / false
autoBackClick the left area (back icon), whether to automatically return to the previous pageBooleanfalsetrue / false
leftIconThe name of the icon returned on the left, only the icon that comes with wu-uiStringarrow-left-
leftTextleft tooltip textString--
rightIconThe name of the icon returned on the right side, which can only be the icon that comes with wu-uiString--
rightTextthe prompt text on the right sideString--
titlenavigation bar title, if it is set to an empty character, it will hide the title occupying areaString--
bgColorNavigation bar background settingString#ffffff-
titleWidthThe maximum width of the title of the navigation bar, if the content exceeds it, it will be hidden with an ellipsis, unit rpxString / Number400rpx-
heightThe height of the navigation bar (not including the height of the status bar, automatically added internally), in pxString / Number44px-
leftIconSizeLeft icon sizeString / Number20px-
leftIconColorThe color of left icon returnedString#303133-
titleStylestyle of title, object or stringString / Object--
customStyleDefine the external style that needs to be usedString / Object--
method namedescriptioncallback parameters
leftClickClick on the left area-
rightClickClick on the right area-
NameDescription
leftCustomize the content on the left side
rightCustomize part of the content on the right
centerCustomize the middle content