uniapp顶部导航栏及按钮的自定义事件

uniapp顶部按钮和搜索框

先看效果图
在这里插入图片描述

效果是怎样实现的呢?(这个只支持APP和一些H5页面)
uniapp的官方文档文档地址,在文档中搜索app-plus,就可以找到对应的属性。

实现步骤

  1. page.json中找到对应的页面。
  2. 在对应页面的style中添加如下代码

在这里插入图片描述

 "app-plus": {
                     "bounce": "none",
                     "titleNView": {
                         "buttons": [ 
                             {
                                 "text": "···",
                                 "fontSize":"16",
                                 "float": "right",
                                 "color":"#101010"
                             },
                             {
                                 "text": "城市", 
								 "fontSrc":"",
                                 "fontSize":"16",
                                 "float": "left",
                                 "color":"#101010"
                             }
                         ],
                         "searchInput":{
                                 "align": "center",
                                 "placeholder": "请输入查找专家信息", 
								 "border": "2upx solid #EC5D29"
                             }
                     }
                 }

顶部按钮以及搜索框的监听事件

在这里插入图片描述
这个uniapp官方也是给的有文档的,安排的明明白白的。文档地址
这个方法和data,onload同级(优先级都是在同一级)。列如:
在这里插入图片描述

动态设置顶部导航的内容

这些东西uniapp官方的文档基本都是有的文档地址

这个就不是跟onload,data这些方法平级了。一般都是在onReady内执行,以避免被框架内的修改所覆盖。如果必须在onShow内执行需要延迟一小段时间。(建议在onReady内执行)。
在这里插入图片描述

		uni.setNavigationBarTitle({
				title:"页面标题内容"
			})
		uni.setNavigationBarColor({ //16进制
			    frontColor: '字体颜色',
			    backgroundColor: '背景颜色',
			})
Uniapp中可以通过使用自定义组件来实现自定义顶部导航栏。以下是一个简单的示例: 1. 在Uniapp项目中创建一个自定义组件,例如命名为"custom-nav"。 2. 在"custom-nav"组件中添加一个顶部导航栏的布局,例如: ```html <template> <view class="nav-wrapper"> <view class="nav-left"> <!-- 左侧按钮 --> </view> <view class="nav-title"> {{ title }} </view> <view class="nav-right"> <!-- 右侧按钮 --> </view> </view> </template> <style> .nav-wrapper { display: flex; justify-content: space-between; align-items: center; height: 44px; background-color: #fff; border-bottom: 1px solid #eee; } .nav-left, .nav-right { width: 50px; height: 100%; display: flex; justify-content: center; align-items: center; } .nav-title { flex: 1; text-align: center; font-size: 16px; font-weight: bold; } </style> ``` 3. 在父组件中使用"custom-nav"组件,并在"custom-nav"组件中传递标题和按钮等参数,例如: ```html <template> <view class="container"> <custom-nav title="自定义导航栏" :showLeftButton="true" :showRightButton="true" /> <!-- 页面内容 --> </view> </template> <script> import CustomNav from '@/components/custom-nav/index.vue'; export default { components: { CustomNav } } </script> <style> .container { padding-top: 44px; /* 需要加上导航栏高度 */ } </style> ``` 4. 在"custom-nav"组件中通过props接收父组件传递的参数,并在模板中根据参数来显示或隐藏左右按钮等,例如: ```html <template> <view class="nav-wrapper"> <view class="nav-left" v-if="showLeftButton"> <!-- 左侧按钮 --> </view> <view class="nav-title"> {{ title }} </view> <view class="nav-right" v-if="showRightButton"> <!-- 右侧按钮 --> </view> </view> </template> <script> export default { props: { title: { type: String, default: '' }, showLeftButton: { type: Boolean, default: false }, showRightButton: { type: Boolean, default: false } } } </script> ``` 这样就可以在Uniapp中实现自定义顶部导航栏了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我不是码神(dn)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值