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

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.mrgr.cn/news/36622.html

相关文章:

  • 如何降低供应链物流成本
  • 数据的表示和存储 第4讲 C语言中的浮点数的编码表示
  • 三大硬核方式揭秘:Java如何与底层硬件和工业设备轻松通信!
  • python 实现multilayer perceptron classifier多层感知器分类器算法
  • AI大模型全套学习资料
  • 安全开发指南
  • 桌面整理工具:电脑桌面如何不显示任何东西?一键整理!
  • golang qq邮件发送验证码
  • 24最新ComfyUI搭建使用教程
  • 一文详解大模型微调与小模型训练
  • ComfyUI 节点、插件的基本指南
  • 什么Python库处理大量数据比较快?
  • 如何构建鲁棒高性能 Prompt 的方法?
  • [极客大挑战 2019]RCE ME1
  • 区间估计通俗理解与理论推导
  • ES的自我保护机制,磁盘超过多少会进入只读模式,怎么解决
  • JS设计模式之桥接模式:搭建跨越维度的通路
  • trixbox call php发起电话呼叫
  • AI:颠覆式创新 vs. 持续性创新
  • 轻松上手MyBatis反向工程:从零到一的自动化代码生成