Navbar
组件类型:UxNavbarComponentPublicInstance
支持左右插槽,更多自定义样式
平台兼容性
UniApp X
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
√ | √ | √ | x | √ |
UniApp Vue Nvue
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
x | x | √ | x | x |
Props
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
left | Slot | 左侧插槽 | |
title | Slot | 标题插槽 | |
right | Slot | 右侧插槽 | |
title | String | 标题 | |
alignLeft | Boolean | false | 标题居左 |
color | String | $ux.Conf.titleColor | 标题颜色 |
darkColor | String | 深色none-不显示,auto-自动适配深色模式,其他-颜色 | |
size | Any | $ux.Conf.fontSize | 字体大小 |
bold | Boolean | false | 字体加粗 |
height | Any | 44 | 导航栏高度 |
border | Boolean | true | 显示下边框 |
borderColor | String | $ux.Conf.borderColor | 下边框颜色 |
colors | Array | 背景色多个渐变 | |
gradientDirection | String | bottom | 渐变色方向 |
background | String | 背景图 | |
backgroundMode | String | aspectFill | 背景图裁剪模式 |
showBlur | Boolean | false | 开启模糊背景 |
blurRadius | Number | 10 | 模糊半径 |
blurAlpha | Number | 0.5 | 模糊透明度 |
fixed | Boolean | false | 固定定位 |
zIndex | Number | 10000 | 层级z-index |
goback | Boolean | true | 显示返回按钮 |
gobackText | String | 返回按钮文字 |
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>