Skip to content
本页导读

Navbar

组件类型:UxNavbarComponentPublicInstance

支持左右插槽,更多自定义样式

平台兼容性

UniApp X

AndroidiOSweb鸿蒙 Next小程序
x

UniApp Vue Nvue

AndroidiOSweb鸿蒙 Next小程序
xxxx

Props

属性名类型默认值说明
leftSlot左侧插槽
titleSlot标题插槽
rightSlot右侧插槽
titleString标题
alignLeftBooleanfalse标题居左
colorString$ux.Conf.titleColor标题颜色
darkColorString深色none-不显示,auto-自动适配深色模式,其他-颜色
sizeAny$ux.Conf.fontSize字体大小
boldBooleanfalse字体加粗
heightAny44导航栏高度
borderBooleantrue显示下边框
borderColorString$ux.Conf.borderColor下边框颜色
colorsArray背景色多个渐变
gradientDirectionStringbottom渐变色方向
backgroundString背景图
backgroundModeStringaspectFill背景图裁剪模式
showBlurBooleanfalse开启模糊背景
blurRadiusNumber10模糊半径
blurAlphaNumber0.5模糊透明度
fixedBooleanfalse固定定位
zIndexNumber10000层级z-index
gobackBooleantrue显示返回按钮
gobackTextString返回按钮文字

darkColor

说明
none不显示
auto自动适配深色模式
color其他颜色

gradientDirection

说明
top向上
bottom向下
left向左
right向右

backgroundMode

说明
scaleToFill不保持纵横比缩放图片,使图片的宽高完全拉伸至填满image元素
aspectFit保持纵横比缩放图片,使图片的长边能完全显示出来。也就是说,可以完整地将图片显示出来
aspectFill保持纵横比缩放图片,只保证图片的短边能完全显示出来。也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取
widthFix宽度不变,高度自动变化,保持原图宽高比不变
heightFix高度不变,宽度自动变化,保持原图宽高比不变
top不缩放图片,只显示图片的顶部区域
bottom不缩放图片,只显示图片的底部区域
center不缩放图片,只显示图片的中间区域
left不缩放图片,只显示图片的左边区域
right不缩放图片,只显示图片的右边区域
topleft不缩放图片,只显示图片的左上边区域
topright不缩放图片,只显示图片的右上边区域
bottomleft不缩放图片,只显示图片的左下边区域
bottomright不缩放图片,只显示图片的右下边区域

示例代码

html
<template>
	<ux-page :stack="showDoc">
		<ux-navbar :title="title" :border="false" :fixed="true" :show-blur="true" :zIndex="100000">
			<template v-slot:right>
				<!-- #ifndef MP -->
				<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
				<!-- #endif -->
			</template>
		</ux-navbar>
		
		<ux-scroll>
			<ux-placeholder :navbar="true"></ux-placeholder>
			
			<ux-card direction="column" icon="flag-filled" title="顶部导航栏" :bold="true">
				<ux-text text="支持左右插槽,更多自定义样式"></ux-text>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="标题居左" :bold="true">
				<ux-navbar title="首页" :alignLeft="true" :border="false">
					<template v-slot:right>
						<ux-row :mr="5" justify="right" align="center">
							<ux-button theme="text" icon="sharing-filled"></ux-button>
							<ux-button theme="text" icon="setting-filled"></ux-button>
						</ux-row>
					</template>
				</ux-navbar>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="右侧插槽" :bold="true">
				<ux-navbar title="首页">
					<template v-slot:right>
						<ux-row :mr="5" justify="right" align="center">
							<ux-button theme="text" icon="sharing-filled"></ux-button>
							<ux-button theme="text" icon="setting-filled"></ux-button>
						</ux-row>
					</template>
				</ux-navbar>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="左侧插槽" :bold="true">
				<ux-navbar title="首页" :border="true">
					<template v-slot:left>
						<ux-icon type="close" :size="16" :ml="15"></ux-icon>
					</template>
				</ux-navbar>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="返回文案" :bold="true">
				<ux-navbar title="首页" gobackText="上一页" borderColor="red"></ux-navbar>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="不显示返回按钮" :bold="true">
				<ux-navbar title="首页" :goback="false"></ux-navbar>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="背景图" :bold="true">
				<ux-row>
					<ux-navbar title="首页" color="white" background="/static/navbar.png" backgroundMode="aspectFill" :border="false"></ux-navbar>
				</ux-row>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="上下渐变" :bold="true">
				<ux-row>
					<ux-navbar title="首页" color="white" :colors="['yellow', 'green']" :border="false"></ux-navbar>
				</ux-row>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="左右渐变" :bold="true">
				<ux-row>
					<ux-navbar title="首页" color="white" :colors="['yellow', 'green']" gradientDirection="right" :border="false"></ux-navbar>
				</ux-row>
			</ux-card>
			
			<ux-placeholder :height="200">
				<ux-row justify="center" align="center" style="height: 100%;">
					<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
				</ux-row>
			</ux-placeholder>
		</ux-scroll>
	</ux-page>
</template>
<template>
	<ux-page :stack="showDoc">
		<ux-navbar :title="title" :border="false" :fixed="true" :show-blur="true" :zIndex="100000">
			<template v-slot:right>
				<!-- #ifndef MP -->
				<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
				<!-- #endif -->
			</template>
		</ux-navbar>
		
		<ux-scroll>
			<ux-placeholder :navbar="true"></ux-placeholder>
			
			<ux-card direction="column" icon="flag-filled" title="顶部导航栏" :bold="true">
				<ux-text text="支持左右插槽,更多自定义样式"></ux-text>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="标题居左" :bold="true">
				<ux-navbar title="首页" :alignLeft="true" :border="false">
					<template v-slot:right>
						<ux-row :mr="5" justify="right" align="center">
							<ux-button theme="text" icon="sharing-filled"></ux-button>
							<ux-button theme="text" icon="setting-filled"></ux-button>
						</ux-row>
					</template>
				</ux-navbar>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="右侧插槽" :bold="true">
				<ux-navbar title="首页">
					<template v-slot:right>
						<ux-row :mr="5" justify="right" align="center">
							<ux-button theme="text" icon="sharing-filled"></ux-button>
							<ux-button theme="text" icon="setting-filled"></ux-button>
						</ux-row>
					</template>
				</ux-navbar>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="左侧插槽" :bold="true">
				<ux-navbar title="首页" :border="true">
					<template v-slot:left>
						<ux-icon type="close" :size="16" :ml="15"></ux-icon>
					</template>
				</ux-navbar>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="返回文案" :bold="true">
				<ux-navbar title="首页" gobackText="上一页" borderColor="red"></ux-navbar>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="不显示返回按钮" :bold="true">
				<ux-navbar title="首页" :goback="false"></ux-navbar>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="背景图" :bold="true">
				<ux-row>
					<ux-navbar title="首页" color="white" background="/static/navbar.png" backgroundMode="aspectFill" :border="false"></ux-navbar>
				</ux-row>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="上下渐变" :bold="true">
				<ux-row>
					<ux-navbar title="首页" color="white" :colors="['yellow', 'green']" :border="false"></ux-navbar>
				</ux-row>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="左右渐变" :bold="true">
				<ux-row>
					<ux-navbar title="首页" color="white" :colors="['yellow', 'green']" gradientDirection="right" :border="false"></ux-navbar>
				</ux-row>
			</ux-card>
			
			<ux-placeholder :height="200">
				<ux-row justify="center" align="center" style="height: 100%;">
					<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
				</ux-row>
			</ux-placeholder>
		</ux-scroll>
	</ux-page>
</template>
ts
<script setup>
	
	import * as plus from '@/uni_modules/ux-plus'
	
	const title = ref('')
	
	const showDoc = ref(false)
	
	function onDoc() {
		plus.openWeb({
			title: '在线文档',
			url: 'https://www.uxframe.cn/component/navbar.html',
			// blur: 1,
			success: () => {
				showDoc.value = true
			},
			complete: () => {
				showDoc.value = false
			}
		})
	}
	
	onLoad((e) => {
		title.value = e['title'] ?? ''
	})
</script>
<script setup>
	
	import * as plus from '@/uni_modules/ux-plus'
	
	const title = ref('')
	
	const showDoc = ref(false)
	
	function onDoc() {
		plus.openWeb({
			title: '在线文档',
			url: 'https://www.uxframe.cn/component/navbar.html',
			// blur: 1,
			success: () => {
				showDoc.value = true
			},
			complete: () => {
				showDoc.value = false
			}
		})
	}
	
	onLoad((e) => {
		title.value = e['title'] ?? ''
	})
</script>
css
<style lang="scss">
	
</style>
<style lang="scss">
	
</style>