NavBar Navigation bar
Display page titles, back navigation and trailing actions.
Import
Use <hui-nav-bar> with uni-app easycom. Import public types from @nscode/handy-uni. For ordinary Vue 3, install the preview plugin from @nscode/handy-uni/web and register its components.
Examples
Interact with the controls to see values and event results on the page.
vue
<template>
<view>
<hui-nav-bar
title="页面标题 / Page title"
left-text="返回 / Back"
right-text="保存 / Save"
left-arrow
:auto-back="false"
@click-left="event0"
@click-right="event1"
@back-root="event2"
/>
<hui-nav-bar title="自定义 / Custom" :safe-area-inset-top="false"
><template #right><hui-icon name="search" label="搜索 / Search" /></template
></hui-nav-bar>
<text>{{ lastEvent }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('No event yet')
const describe = (value: unknown) => {
try {
return JSON.stringify(value) ?? String(value)
} catch {
return String(value)
}
}
const event0 = (arg0: unknown) => {
lastEvent.value = 'click-left' + ': ' + [describe(arg0)].join(', ')
}
const event1 = (arg0: unknown) => {
lastEvent.value = 'click-right' + ': ' + [describe(arg0)].join(', ')
}
const event2 = () => {
lastEvent.value = 'back-root'
}
</script>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | — | Title. |
leftArrow | boolean | false | Show the back arrow. |
leftText | string | — | Leading action text. |
rightText | string | — | Trailing action text. |
autoBack | boolean | true | Call the router adapter automatically from the back action. |
fixed | boolean | false | Use fixed positioning. |
placeholder | boolean | false | Placeholder when no value is selected or entered. |
safeAreaInsetTop | boolean | true | Reserve the top safe area. |
avoidCapsule | boolean | true | Reserve space for the WeChat capsule. |
border | boolean | true | Show a border or separator. |
zIndex | number | 10 | Layer z-index; allocated from the current page stack when omitted. |
leftDisabled | boolean | false | Disable the leading action. |
rightDisabled | boolean | false | Disable the trailing action. |
Root attributes: common props. A Boolean default of undefined supports inheritance; explicit false overrides it. Other Boolean props default to false unless listed otherwise.
Events
| Event | Parameters | Description |
|---|---|---|
click-left | (event: unknown) | Reports the corresponding interaction result. |
click-right | (event: unknown) | Reports the corresponding interaction result. |
back-root | () | Reports the corresponding interaction result. |
Slots
| Slot | Parameters | Description |
|---|---|---|
left | — | Custom left region; replaces its fallback content. |
title | — | Custom title region; replaces its fallback content. |
right | — | Custom right region; replaces its fallback content. |
Methods
None.
Types
NavBarProps、NavBarEmits are available from @nscode/handy-uni.
Platform notes
| Behavior | uni-app H5 | WeChat Mini Program | App-vue | Ordinary Vue 3 Web (preview) |
|---|---|---|---|---|
| Basic interaction | Supported; device checks pending | Supported; device checks pending | Supported; device checks pending | Supported by the web platform adapter |
| Status bar and capsule | No capsule | useSafeArea retries a missing cold-start reading; no extra onReady query | Native status-bar metrics | Zero status-bar height and no capsule; autoBack uses available browser history |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.