uniapp 微信小程序导航栏不起作用

uni-app导航只需要在pages.json里面修改app-plus

		{
			"path": "pages/index/index",
			"style": {
				"app-plus":{
					"scrollIndicator":"none",
					"titleNView":{
						"searchInput":{
							"align":"center",
							"backgroundColor":"#F7F7F7",
							"borderRadius":"4px",
							"placeholder":"搜索爱宠",
							"placeholderColor":"#CCCCCC",
							"disabled":false
						}	
					}
				}
			}
		}

但是在小程序中不起作用,想要自定义导航栏要用别的方法,我用的是使用组件的方法。

首先新建一个项目,选择的是uniapp的模板,选中hello uni-app,创建

然后,将components这个文件夹,整个文件夹复制到我们的项目中,和pages同一级目录,在<script></script>中引入组件

<script>
import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
export default {
	components:{
	    uniNavBar
	}
}
</script>

页面的写法,我这里是写了个input框,不需要input框的小伙伴也可以去掉,然后在组件里面可以设置title,backgroungcolor等。

<template>
	<view>
		<!-- 头部搜索框 -->
		<view class="content">
			<uni-nav-bar leftIcon="camera" rightIcon="search" color="black">
				<input placeholder="搜索爱宠" style="border: none;"/>
			</uni-nav-bar>
		</view>
    </view>
</template>

做出来的效果是这样的

 将input去掉,设置为导航栏的写法如下,不需要leftIcon的可以去掉

<uni-nav-bar leftIcon="camera" rightIcon="search" color="black" title="首页" background-color="#00c170">
</uni-nav-bar>

效果如下,长度可以自己设置

 --------------------------------------------------------------------------------------------------

 

这里补充一点,引入组件的还有个好处就是可以直接引用里面的icon,美化我们的页面,当然你也可以引入第三方工具,阿里巴巴图库等,因为icon还是相对来说比较少点。我们可以在components>uni-icons>icons.js下寻找我们需要的icon。

export default {
	"pulldown": "\ue588",
	"refreshempty": "\ue461",
	"back": "\ue471",
	"forward": "\ue470",
	"more": "\ue507",
	"more-filled": "\ue537",
	"scan": "\ue612",
	"qq": "\ue264",
	"weibo": "\ue260",
	"weixin": "\ue261",
	"pengyouquan": "\ue262",
	"loop": "\ue565",
	"refresh": "\ue407",
	"refresh-filled": "\ue437",
	"arrowthindown": "\ue585",
	"arrowthinleft": "\ue586",
	"arrowthinright": "\ue587",
	"arrowthinup": "\ue584",
	"undo-filled": "\ue7d6",
	"undo": "\ue406",
	"redo": "\ue405",
	"redo-filled": "\ue7d9",
	"bars": "\ue563",
	"chatboxes": "\ue203",
	"camera": "\ue301",
	"chatboxes-filled": "\ue233",
	"camera-filled": "\ue7ef",
	"cart-filled": "\ue7f4",
	"cart": "\ue7f5",
	"checkbox-filled": "\ue442",
	"checkbox": "\ue7fa",
	"arrowleft": "\ue582",
	"arrowdown": "\ue581",
	"arrowright": "\ue583",
	"smallcircle-filled": "\ue801",
	"arrowup": "\ue580",
	"circle": "\ue411",
	"eye-filled": "\ue568",
	"eye-slash-filled": "\ue822",
	"eye-slash": "\ue823",
	"eye": "\ue824",
	"flag-filled": "\ue825",
	"flag": "\ue508",
	"gear-filled": "\ue532",
	"reload": "\ue462",
	"gear": "\ue502",
	"hand-thumbsdown-filled": "\ue83b",
	"hand-thumbsdown": "\ue83c",
	"hand-thumbsup-filled": "\ue83d",
	"heart-filled": "\ue83e",
	"hand-thumbsup": "\ue83f",
	"heart": "\ue840",
	"home": "\ue500",
	"info": "\ue504",
	"home-filled": "\ue530",
	"info-filled": "\ue534",
	"circle-filled": "\ue441",
	"chat-filled": "\ue847",
	"chat": "\ue263",
	"mail-open-filled": "\ue84d",
	"email-filled": "\ue231",
	"mail-open": "\ue84e",
	"email": "\ue201",
	"checkmarkempty": "\ue472",
	"list": "\ue562",
	"locked-filled": "\ue856",
	"locked": "\ue506",
	"map-filled": "\ue85c",
	"map-pin": "\ue85e",
	"map-pin-ellipse": "\ue864",
	"map": "\ue364",
	"minus-filled": "\ue440",
	"mic-filled": "\ue332",
	"minus": "\ue410",
	"micoff": "\ue360",
	"mic": "\ue302",
	"clear": "\ue434",
	"smallcircle": "\ue868",
	"close": "\ue404",
	"closeempty": "\ue460",
	"paperclip": "\ue567",
	"paperplane": "\ue503",
	"paperplane-filled": "\ue86e",
	"person-filled": "\ue131",
	"contact-filled": "\ue130",
	"person": "\ue101",
	"contact": "\ue100",
	"images-filled": "\ue87a",
	"phone": "\ue200",
	"images": "\ue87b",
	"image": "\ue363",
	"image-filled": "\ue877",
	"location-filled": "\ue333",
	"location": "\ue303",
	"plus-filled": "\ue439",
	"plus": "\ue409",
	"plusempty": "\ue468",
	"help-filled": "\ue535",
	"help": "\ue505",
	"navigate-filled": "\ue884",
	"navigate": "\ue501",
	"mic-slash-filled": "\ue892",
	"search": "\ue466",
	"settings": "\ue560",
	"sound": "\ue590",
	"sound-filled": "\ue8a1",
	"spinner-cycle": "\ue465",
	"download-filled": "\ue8a4",
	"personadd-filled": "\ue132",
	"videocam-filled": "\ue8af",
	"personadd": "\ue102",
	"upload": "\ue402",
	"upload-filled": "\ue8b1",
	"starhalf": "\ue463",
	"star-filled": "\ue438",
	"star": "\ue408",
	"trash": "\ue401",
	"phone-filled": "\ue230",
	"compose": "\ue400",
	"videocam": "\ue300",
	"trash-filled": "\ue8dc",
	"download": "\ue403",
	"chatbubble-filled": "\ue232",
	"chatbubble": "\ue202",
	"cloud-download": "\ue8e4",
	"cloud-upload-filled": "\ue8e5",
	"cloud-upload": "\ue8e6",
	"cloud-download-filled": "\ue8e9",
	"headphones":"\ue8bf",
	"shop":"\ue609"
}

有写得不够好的,望指正。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: Uniapp是一款多端开发框架,支持开发微信小程序、H5、App等多种平台的应用程序。在微信小程序中,往往需要自定义导航栏以满足用户需求,Uniapp提供了方便易用的方法来实现此功能。 首先,在Uniapp中创建一个自定义导航栏的组件,可以使用vue组件进行实现。在此组件中,需要定义导航栏的样式,例如背景颜色、文字颜色、边框等。 其次,在每个需要自定义导航栏的页面中引入这个组件,并将页面的标题传递给组件。这样,在页面中就可以显示出我们定义的自定义导航栏了。 除此之外,我们还可以在这个组件中添加返回按钮、菜单按钮等功能,以提升用户体验。同时,还可以通过uni.getSystemInfoSync()方法获取系统信息来动态设置导航栏的高度,以兼容不同设备的屏幕尺寸。 总之,Uniapp提供了方便简洁的方法来实现自定义导航栏,在微信小程序开发中非常实用。通过此功能,我们可以为用户提供更加个性化、更加舒适的应用体验。 ### 回答2: Uniapp 是一款跨平台的开发框架,可以快速开发出支持多种小程序平台的应用,包括微信小程序。在微信小程序中,自定义导航栏能够提供更好的用户体验,同时也满足了开发者个性化设计的需求。下面将介绍如何在 Uniapp 中自定义微信小程序导航栏。 1. 使用插件方式 Uniapp 提供了一个可以自定义导航栏的插件 uni-navigationBar,可以方便地进行开发。使用该插件的步骤如下: (1)安装 uni-navigationBar 插件 在 HBuilderX 的插件市场搜索 uni-navigationBar 并安装。或者在项目根目录下执行以下命令: npm install --save uni-navigationbar (2)在需要使用自定义导航栏的页面引入插件 在需要使用自定义导航栏的页面的 script 标签中,引入插件并注册: import uniNavigationBar from 'uni-navigationbar/vue'; Vue.use(uniNavigationBar); (3)在页面中使用自定义导航栏 可以在页面的 template 标签中,使用 uni-navigationBar 提供的组件和组件属性来实现自定义导航栏。 2. 使用自定义组件方式 如果不想使用插件,也可以自己编写一个自定义组件来实现自定义导航栏。实现的步骤如下: (1)在项目中创建自定义组件 可以使用 HBuilderX 的“创建自定义组件”功能,在项目中创建一个自定义组件。 (2)在自定义组件中编写导航栏代码 可以在自定义组件的 template 标签中编写需要自定义的导航栏代码。 (3)在需要使用自定义导航栏的页面引入自定义组件 在需要使用自定义导航栏的页面的 template 标签中,引入刚才创建的自定义组件。 (4)在页面中使用自定义导航栏 可以在页面的 template 标签中,使用刚才创建的自定义组件,来实现自定义导航栏。 总的来说,Uniapp 微信小程序自定义导航栏的实现方法比较简单。可以使用插件方式或者自定义组件方式。如果你的项目已经使用 uni-navigationBar 插件,可以直接使用该插件实现自定义导航栏;如果你需要自定义更多的样式或交互效果,可以自己编写一个自定义组件。在实际开发中,可以根据项目需求和个人喜好选择适合自己的方式来实现自定义导航栏。 ### 回答3: Uniapp 是一款跨端应用开发框架,可以同时开发出运行于多个平台的应用程序。在 Uniapp 中,为了更好地适应不同平台的导航栏样式需求,Uniapp 提供了一套自定义导航栏的解决方案。本文将介绍如何使用 Uniapp 的自定义导航栏功能来开发微信小程序Uniapp 提供了两种自定义导航栏的方式:native 和 js 组件两种方式。 1. native 方式: 使用 native 方式,可以直接使用小程序原生的导航栏组件,Uniapp 会提供一些额外的 API、样式、事件来方便我们在开发过程中进行调整。 2. js 组件方式: 使用 js 组件方式,可以完全自定义导航栏的样式和行为,包括可以将导航栏设置为全局组件,方便在应用程序的多个页面中复用和调用。 下面我们将以 js 组件方式为例,介绍如何使用 Uniapp 的自定义导航栏功能来开发微信小程序。 第一步,在 App.vue 中定义自定义导航栏组件: ``` <template> <view class="app"> <!-- 引入自定义导航栏组件 --> <custom-nav-bar title="自定义导航栏"></custom-nav-bar> <!-- 页面内容 --> <router-view></router-view> </view> </template> <script> export default { components: { // 引入自定义导航栏组件 'custom-nav-bar': () => import('@/components/CustomNavBar.vue') } } </script> <style> /* 自定义导航栏样式 */ .uni-nav-bar { height: uni-status-bar-height + 44px; padding-top: uni-status-bar-height; display: flex; justify-content: center; align-items: center; background-color: #fff; color: #000; position: relative; z-index: 100; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .uni-nav-bar__title { font-size: 18px; } </style> ``` 第二步,定义自定义导航栏组件的样式和功能: ``` <template> <view class="uni-nav-bar"> <!-- 导航栏左侧返回按钮 --> <view class="uni-nav-bar__left" @tap="back"> <text class="uni-nav-bar__back">返回</text> </view> <!-- 导航栏标题 --> <view class="uni-nav-bar__title">{{ title }}</view> </view> </template> <script> export default { props: ['title'], methods: { // 导航栏左侧返回按钮点击事件 back () { uni.navigateBack() } } } </script> <style> /* 导航栏样式 */ .uni-nav-bar { height: 44px; padding: 0 16px; display: flex; justify-content: space-between; align-items: center; background-color: #fff; color: #000; position: relative; z-index: 100; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .uni-nav-bar__left { width: 70px; display: flex; flex-direction: row; justify-content: flex-start; align-items: center; } .uni-nav-bar__back { font-size: 16px; color: #000; } .uni-nav-bar__title { font-size: 18px; } </style> ``` 以上即为使用 Uniapp 的自定义导航栏功能来开发微信小程序的完整示例。通过以上代码,我们定义了一个自定义导航栏组件 CustomNavBar,并且在 App.vue 中引入和展示了该组件。 在实际开发过程中,我们可以根据自己的需求来调整自定义导航栏的样式和功能,比如在导航栏右侧添加按钮、增加搜索栏等等。同时,也可以将自定义导航栏组件设置为全局组件,方便在应用程序的多个页面中复用和调用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值