uni-app自定义底部切换栏tabBar

本文详细介绍了一种使用uniApp框架实现底部导航栏的方法,包括组件的创建、样式设置及功能实现,如导航跳转等,适用于小程序和移动端应用开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
	<view class="footer-bar">
		<view class="bar-list">
			<view class="bar-item" :class="item.active?'bar-item-active':''" v-for="(item,index) in listData" :key="index" @click="tabClick(item.url)">
				<image :src="item.image" class="item-icon"></image>
				{{item.name}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			};
		},
		props:{
			listData:{
				type:Array,
				value:[]
			}
		},
		methods:{
			tabClick: function(url){
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss">
	.footer-bar {
		.bar-list {
			width: 100%;
			height: 100rpx;
			position: fixed;
			bottom: 0;
			left: 0;
			display: flex;
			justify-content: space-around;
			align-items: center;
			background:rgba(255,255,255,1);
			box-shadow:0px 0px 0px 0px rgba(0,0,0,0.1);
			
			.bar-item{
				text-align: center;
				font-size:20rpx;
				font-family:PingFangSC-Regular,PingFang SC;
				font-weight:400;
				color:rgba(50,60,73,1);
				text-align: center;
				
				.item-icon{
					display: block;
					width: 44rpx;
					height:44rpx;
					margin: 0 auto 8rpx auto;
				}
			}
			
			.bar-item-active{
				color:rgba(102,166,255,1);
			}
		}
	}
</style>

 

引用:

import uiTabBar from '@/components/ui-tab-bar/ui-tab-bar.vue'

components: {
              uiTabBar
        }

listData: [{
                        name: '工作',
                        url: '../index/index',
                        image: '/static/image/gz_s.png',
                        active: true,
                    },
                    {
                        name: '功能',
                        url: '../function/function',
                        image: '/static/image/work.png',
                        active: false,
                    },
                    {
                        name: '通讯录',
                        url: '../book/book',
                        image: '/static/image/book.png',
                        active: false,
                    }, {
                        name: '我的',
                        url: '../myhome/myhome',
                        image: '/static/image/myhome.png',
                        active: false,
                    }
                ],

页面:  <ui-tab-bar :listData="listData"></ui-tab-bar>

 

效果:

 

uni-app中,可以通过自定义底部tabbar组件来实现切换动画效果。首先,在tab-bar组件中,可以使用unitabbar组件来实现底部tab切换功能。在tab-bar组件中,可以通过设置backgroundColor属性,color属性和tintColor属性来自定义底部tabbar的背景颜色,字体颜色和选中状态的图标高亮颜色。接着,在methods中的tabClick方法中,可以使用uni的redirectTo方法来进行tab页的跳转,并将当前tab的高亮索引更新为点击的tab的索引。这样,当点击底部tab时,页面会实现切换动画效果并跳转到对应的tab页。同时,可以根据自己的需求添加一些额外的功能,如实现tab的数字角标和tab页面的跳转。例如,在基础上可以添加tab的数字角标和tab页面跳转功能。为了保证底部tabbar的高度一致,可以在全局的数据中设置一个tabbarHeight属性,并在tab-bar组件中引用该属性。这样,就可以实现自定义底部tabbar切换动画效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [H5版基于uni-app实现自定义底部tabbar效果(支持底部图标选中时的渐变效果)](https://blog.youkuaiyun.com/CherryLee_1210/article/details/106281571)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [uni-app 自定义底部导航的实现](https://blog.youkuaiyun.com/weixin_32786041/article/details/111911595)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值