欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > uniapp自定义底部tabBar

uniapp自定义底部tabBar

2024/10/25 19:25:47 来源:https://blog.csdn.net/qq_53024519/article/details/142552142  浏览:    关键词: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.页面跳转后会重绘底部导航栏,出现闪的问题

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com