[保姆级教程]uniapp自定义导航栏

文章目录


导文

在 UniApp 中,自定义导航栏通常涉及到隐藏默认的导航栏,并在页面顶部添加自定义的视图组件来模拟导航栏的功能。

隐藏默认导航栏:

全局隐藏

在你的页面 pages.json 配置中,为相应的页面设置 navigationStylecustom,这将隐藏默认的导航栏。

json 复制代码
  	"globalStyle": {
		"navigationStyle": "custom"
	},

当前页面隐藏

json 复制代码
   {
     "pages": [
       {
         "path": "pages/index/index",
         "style": {
           "navigationStyle": "custom"
         }
       },
       // ... 其他页面配置
     ]
   }

添加自定义导航栏视图:

手写导航栏

在你的页面 .vue 文件中,使用 <view><template> 标签在页面顶部添加自定义的导航栏视图。这可以包括标题文本、返回按钮、搜索框等。

html 复制代码
   <template>
     <view class="container">
       <view class="custom-nav-bar">
         <text class="back-button" @click="goBack">返回</text>
         <text class="title">标题</text>
         <!-- 这里可以添加其他导航栏元素 -->
       </view>
       <!-- 页面内容 -->
       <view class="content">
         <!-- ... -->
       </view>
     </view>
   </template>

   <script>
   export default {
     methods: {
       goBack() {
         uni.navigateBack();
       },
       // ... 其他方法
     }
   };
   </script>

   <style>
   .custom-nav-bar {
     display: flex;
     justify-content: space-between;
     align-items: center;
     height: 44px; /* 根据需要调整高度 */
     background-color: #fff; /* 导航栏背景色 */
     /* 其他样式属性 */
   }
   .back-button {
     /* 返回按钮样式 */
   }
   .title {
     /* 标题样式 */
   }
   /* 其他样式 */
   </style>

组件导航栏

使用uinapp原生的组件

dart 复制代码
<template>
	<view class="checkIn">
		
		<view class="checkIn-date">
			<uni-nav-bar dark :fixed="true" shadow background-color="#007AFF" status-bar left-icon="left" left-text="返回"
			title="自定义导航栏" @clickLeft="back" />
		</view>
		<view class="checkIn-main">
			<uni-card title="标题文字" thumbnail="" extra="额外信息" note="Tips">
				内容主体,可自定义内容及样式
			</uni-card>
		</view>
	</view>
</template>

<script>
	
export default {
	components: {
	
	},
	data() {
		return {

		}
	},
	onReady() {

	},
	methods: {

	}
}
</script>

<style>

</style>


官网详细配置》》

您好,我是肥晨。

欢迎关注我获取前端学习资源,日常分享技术变革,生存法则;行业内幕,洞察先机。

相关推荐
游戏开发爱好者85 小时前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
2501_915106327 小时前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106327 小时前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
宠友信息8 小时前
2025社交+IM及时通讯社区APP仿小红书小程序
java·spring boot·小程序·uni-app·web app
“负拾捌”9 小时前
python + uniapp 结合腾讯云实现实时语音识别功能(WebSocket)
python·websocket·微信小程序·uni-app·大模型·腾讯云·语音识别
局外人LZ1 天前
Uniapp脚手架项目搭建,uniapp+vue3+uView pro+vite+pinia+sass
前端·uni-app·sass
2501_915918411 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
前端呆头鹅1 天前
Websocket使用方案详解(uniapp版)
websocket·网络协议·uni-app
浮桥1 天前
uniapp+h5 公众号实现分享海报绘制
uni-app·notepad++
2501_916007471 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview