uniapp自定义底部tabBar

news/2024/9/29 16:11:42 标签: uni-app, 自定义tabbar

使用场景:在一个非tabbar页面,想要有底部导航效果,故自定义效果,系统原底部导航栏仍在正常使用

效果:

布局:

<template>
	<view class="tab-bar" :style="{height: height + 'px'}">
		<view v-for="(item, index) in tabBars" :key="index" @click="switchTab(item)"
			:style="{color: index === selectIndex ? item.selectedTextColor : item.textColor}">
			<view style="display: flex; justify-content: center;">
				<image :src="index === selectIndex ? item.selectedIconPath : item.iconPath" style="height: 25px; width: 25px;"></image>
			</view>
			<view style="margin-top: 2px; font-size: 12px;">
				{{item.text}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"tabBar",
		props: {
			tabBars: {
				type: Array,
				required: true
			},
			selectIndex: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				height: undefined
			};
		},
		methods: {
			switchTab(item) {
				if (this.getCurrentPageIndex() !== item.pagePath) {
					uni.redirectTo({
						url: item.pagePath
					});
				}
			},
			getCurrentPageIndex() {
				const pages = getCurrentPages();
				return pages[pages.length - 1].route;
			}
		},
		mounted() {
			let systemInfo = uni.getSystemInfoSync();
			let tabBarHeight = systemInfo.screenHeight - systemInfo.windowHeight - systemInfo.statusBarHeight;
			this.height = tabBarHeight
		}
	}
</script>

<style>
.tab-bar {
  display: flex;
  justify-content: space-around;
  position: fixed;
  height: 5vh;
  bottom: 0;
  width: 100%;
  background-color: #fbfcfe;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  padding-top: 3px;
  padding-bottom: 2px;
}
</style>

使用:

<tabBar :tab-bars="approvalTabbar" :selectIndex="1"></tabBar>
// selectIndex 是当前页面的数组下标
approvalTabbar = [
	{
		iconPath: '/static/icon/mess.png',
		selectedIconPath:'/static/icon/mess-selected.png',
		text: "发起申请",
		pagePath:'/pages/approval/launch/launch',
		textColor: tabTextColor,
		selectedTextColor: tabSelectedTextColor
	},
	{
		iconPath: '/static/icon/approval-mine.png',
		selectedIconPath:'/static/icon/approval-mine-selected.png',
		text: "我审批的",
		pagePath:'/pages/approval/accraditation/accraditation',
		textColor: tabTextColor,
		selectedTextColor: tabSelectedTextColor
	},
	{
		iconPath: '/static/icon/submit.png',
		selectedIconPath:'/static/icon/submit-selected.png',
		text: "已提交",
		pagePath:'/pages/approval/submit/submit',
		textColor: tabTextColor,
		selectedTextColor: tabSelectedTextColor
	}
]

不足之处:

1.需要在参与跳转的每个页面引入组件

2.引入时需要传递相同的tabs数组数据、页面与数组对应的下标

3.页面跳转后会重绘底部导航栏,出现闪的问题


http://www.niftyadmin.cn/n/5683329.html

相关文章

探索存内计算的未来,高能效内存计算实训专场有感~

写在前面&#xff0c;首先感谢活动方&#xff1a;存内计算开发者社区的邀请来参加本次探索存内计算的未来&#xff0c;高能效内存计算实训专场。下面我给大家分享一下本次的活动实操感受&#x1f600;。 活动议程 本次活动邀请存内技术专家李阳老师分享存内计算是什么&#xf…

旭升集团携手纷享销客,构建全方位客户关系管理平台

宁波旭升集团股份有限公司&#xff08;以下简称“旭升集团”&#xff09;自2003年成立&#xff0c;总部位于中国宁波&#xff0c;集团设有压铸、锻造、挤压、集成四大事业部&#xff0c;在亚洲、欧洲、美洲等地均设立研发中心及制造基地&#xff0c;产品主要覆盖新能源汽车的电…

TCP\IP标准与OSI标准

TCP/IP 模型和 OSI 模型都是用于描述网络体系结构的模型&#xff0c;但它们的设计理念和层次结构有所不同。TCP/IP 模型更注重实际实现&#xff0c;而 OSI 模型更注重抽象和标准化。 1. OSI 模型 (Open Systems Interconnection Model) OSI 模型是一个七层模型&#xff0c;从…

常见电脑品牌BIOS设置与进入启动项快捷键

常见电脑品牌BIOS与引导项快捷键速查表 | 电脑品牌 | BIOS快捷键 | 引导项快捷键 | 备注 ||------------|------------|--------------|------------------------------ || 联想 | F2/F1 | F12 | 笔记本通常为F2&#xff0c;台式机通常为F1 || IBM/ThinkPad | F1 | 未知 | ||…

grafana频繁DataSourceError问题

背景 随着 Grafana 数据量的不断增加&#xff0c;逐渐暴露出以下问题&#xff1a; Grafana 页面加载缓慢&#xff1b;Grafana 告警频繁出现 DatasourceError 错误。 对于第一个问题&#xff0c;大家可以参考这篇文章&#xff1a;Grafana 加载缓慢的解决方案。 不过&#xf…

如何帮助我们改造升级原有架构——基于TDengine 平台

一、简介 TDengine 核心是一款高性能、集群开源、云原生的时序数据库&#xff08;Time Series Database&#xff0c;TSDB&#xff09;&#xff0c;专为物联网IoT平台、工业互联网、电力、IT 运维等场景设计并优化&#xff0c;具有极强的弹性伸缩能力。同时它还带有内建的缓存、…

怎么把本地的项目推到github上去

要将本地项目推送到 GitHub 上&#xff0c;可以按照以下步骤操作&#xff1a; 1. 在 GitHub 上创建一个新的仓库 首先&#xff0c;登录你的 GitHub 账号&#xff0c;然后按照以下步骤创建一个新的仓库&#xff1a; 进入 GitHub 网站&#xff0c;点击页面右上角的 “” 按钮&…

腾讯高级研发项目经理胡星受邀为第四届中国项目经理大会演讲嘉宾

全国项目经理专业人士年度盛会 深圳市腾讯计算机系统有限公司CSIG/云产品一部高级研发项目经理胡星先生受邀为PMO评论主办的全国项目经理专业人士年度盛会——2024第四届中国项目经理大会演讲嘉宾&#xff0c;演讲议题为“使命必达、知行合一的项目团队建设实践”。大会将于10月…