当前位置: 首页 > article >正文

uniapp自定义底部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.kler.cn/news/321375.html

相关文章:

  • Spring Boot入门到精通:网上购物商城系统
  • 实用的Git工作流程
  • docker pull镜像失败问题解决尝试
  • 【2】图像视频的加载和显示
  • 通信工程学习:什么是VIM虚拟化基础设施管理器
  • 操作配置笔记
  • 网络与信息安全工程师(工信部教育与考试中心)
  • 【网络安全】Drupal之缓存中毒+储存型XSS
  • 实时湖仓架构演变
  • 【最基础最直观的排序 —— 选择排序算法】
  • 进阶SpringBoot之 Dubbo-admin 安装测试
  • Node-GDAL:简洁强大的Node.js地理空间数据处理库
  • 什么是Node.js?
  • ElasticSearch的安装与使用
  • EasyCVR智慧公园视频智能管理方案:赋能公园安全管理新高度
  • Spring中一些常见注解的作用
  • 使用ucharts写的小程序页面柱状图上方没有数字
  • 7款国内AI搜索引擎大全网站
  • 说说海外云手机的自动化功能
  • [Redis][哨兵][上]详细讲解
  • 深入浅出MongoDB(一)
  • 嵌入式C语言自我修养:GNU C编译器扩展语法精讲
  • 利用Puppeteer-Har记录与分析网页抓取中的性能数据
  • TikTok的网络环境搭建指南
  • C++实现二叉树的创建删除,dfslfs,求叶子结点个数,求叶子结点个数,求树的高度
  • D19【python接口自动化学习】-python基础之内置数据类型
  • 矿石运输船数据集、散货船数据集、普通货船数据集、集装箱船数据集、渔船数据集以及客船数据集
  • Web3Auth 如何工作?
  • 相机、镜头参数详解以及相关计算公式
  • 【OceanBase 诊断调优】—— GC问题根因分析