UniAPP开发,首页底部需展示导航栏,其他页面不需要,如何实现?

一:问题产生

因为公司的业务需求,需要将小程序从A主体公司迁移到B主体公司。

二:说干就干

目的确定好了,就干呗,开始迁移,项目拉取,修改,编译,运行,成功的跑了起来,但是发现与前面发布运行的小程序少了一点啥。没错,就是少了底部导航栏,之前为什么有,为什么现在拉取项目却发现没有,原因只有一个,那就是后面开发的同事把底部导航栏的代码删除后,然后再上传到了代码仓库。

三:问题解决

然后打开文档,发先原生的tabBar即可解决上述问题。

参考文档链接:pages.json 页面路由 | uni-app官网

我也把文档代码copy到这里,里面的属性文档有详细的解释。

"tabBar": {
	"color": "#7A7E83",
	"selectedColor": "#3cc51f",
	"borderStyle": "black",
	"backgroundColor": "#ffffff",
	"list": [{
		"pagePath": "pages/component/index",
		"iconPath": "static/image/icon_component.png",
		"selectedIconPath": "static/image/icon_component_HL.png",
		"text": "组件"
	}, {
		"pagePath": "pages/API/index",
		"iconPath": "static/image/icon_API.png",
		"selectedIconPath": "static/image/icon_API_HL.png",
		"text": "接口"
	}]
}

 注:

  • 这个tabBar代码得放在pages.json里面。
  • tabBar中list中的页面路径,得放在pages里面。

就这样,问题就得到解决咯,细节方面就根据自己的需求,慢慢调整即可。

四:更多的导航栏资源链接就放在下面了

tabbar自定义底部标签栏菜单 - DCloud 插件市场

实现高性能的自定义底部导航栏,可以使用uni-app提供的tabBar组件。tabBar组件可以自定义样式,并且支持通过点击切换页面内容。以下是使用tabBar组件实现自定义底部导航栏的步骤: 1. 在pages.json文件中配置tabBar。 ``` "tabBar": { "color": "#999", "selectedColor": "#007aff", "backgroundColor": "#fff", "borderStyle": "black", "list": [ { "pagePath": "pages/home/home", "text": "首页", "iconPath": "static/tabbar/home.png", "selectedIconPath": "static/tabbar/home-active.png" }, { "pagePath": "pages/category/category", "text": "分类", "iconPath": "static/tabbar/category.png", "selectedIconPath": "static/tabbar/category-active.png" }, { "pagePath": "pages/cart/cart", "text": "购物车", "iconPath": "static/tabbar/cart.png", "selectedIconPath": "static/tabbar/cart-active.png" }, { "pagePath": "pages/mine/mine", "text": "我的", "iconPath": "static/tabbar/mine.png", "selectedIconPath": "static/tabbar/mine-active.png" } ] } ``` 2. 在App.vue文件中设置tabBar的默认样式。 ``` <template> <view> <tab-bar></tab-bar> <router-view></router-view> </view> </template> <script> import TabBar from '@/components/tab-bar/tab-bar.vue' export default { components: { TabBar }, tabBar: { color: '#999', selectedColor: '#007aff', backgroundColor: '#fff', borderStyle: 'black' } } </script> ``` 3. 在tab-bar组件中实现点击切换页面的功能。 ``` <template> <view class="tab-bar"> <view class="tab-item" v-for="(item, index) in list" :key="index" @click="switchTab(index)"> <image :src="item.selected ? item.selectedIconPath : item.iconPath"></image> <text class="tab-title" :class="{active: item.selected}">{{item.text}}</text> </view> </view> </template> <script> export default { props: ['list'], methods: { switchTab(index) { const pages = getCurrentPages() const currentPage = pages[pages.length - 1] const url = '/' + currentPage.route if (index !== this.list.findIndex(item => item.pagePath === url)) { uni.switchTab({ url: '/' + this.list[index].pagePath }) } } } } </script> ``` 通过以上步骤,就可以实现一个高性能的自定义底部导航栏,并且支持点击切换页面内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值