uniapp实现自定义tabbar【直用版】

1.pages.json中将tabBar下面全部注释掉

2.在common文件夹下面建一个tabbar文件夹,里面放个tabbar.vue(位置,名称自己随意)

tabbar.vue:(直接复制)

<template>
	<view class="tabbar">
		<view class="tab" v-for="(item,index) in tabbarList" :key="index" @tap='navigatorTo(item.pagePath)'>			
				<image v-if="item.pagePath === 'release'" :src="item.iconPath" class="addIco" @click="to_release"></image>
				<view  v-else>
					<image v-if="item.pagePath === cureentPage" :src="item.selectedIconPath"></image>
					<image v-else :src="item.iconPath"></image>
				</view>
				<!-- <view class="text"> {{item.text}} </view>		 -->
		</view>
	</view>
</template>
<script>
	export default {
		props:{
			cureentPage:{
				type:String,
				default:'index'
			}
		},		
	}
</script>
<script setup>
	const to_release=()=>{ //跳转发布页面
		uni.navigateTo({
			url:"/pages/release/release"
		})
	}
	const tabbarList=[  //自己定义的tabber
		{
			"pagePath": "index",
			"iconPath": "http://hwww.fun:6060/tabbar/zhu_pi.png",
			"selectedIconPath": "http://hwww.fun:6060/tabbar/zhu1_pi.png",
			"text": "主页"
		},
		{
			"pagePath": "release",
			"iconPath": "http://hwww.fun:6060/tabbar/add.png",
			// "selectedIconPath": "/static/img/tabbar/new2/sort1_pi.png",
			// "text": "发布"
		},
		{
			"pagePath": "myinfo",
			"iconPath": "http://hwww.fun:6060/tabbar/user_pi.png",
			"selectedIconPath": "http://hwww.fun:6060/tabbar/user1_pi.png",
			"text": "你的"
		}
	]
	
	const navigatorTo=(e)=>{  //当点击下方tabbar跳转指定页面
		console.log(e);
			uni.redirectTo({
				url:`../../pages/${e}/${e}`
			})
	}
</script>

<style scoped>
   .tabbar{
	   /* border-top:1rpx solid #c5c4c5; */
	   background-color:#FFFF ;
	   z-index: 999;
	   position: fixed;
	   left: 0;
	   bottom: 0;
	   width: 100%;
	   height: 120rpx;
	   display: flex;
	   justify-content: space-around;
	   align-items: center;
   }
   .tab{
	   display: flex;
	   flex-direction: column;
	   justify-content: center;
	   align-items: center;
   }
   image{
	   width: 50rpx;
	   height: 50rpx;
   }
   .addIco{
	   width: 50px;
	   height: 50px;
   }
</style>

3.在需要用到tabbar的位置(index,myinfo)中引入

index.vue:

<script setup>
    import Tabbar from '@/common/tabbar/tabbar.vue'
</script>

 下面代码直接放当前页面底部就行,注意传递了一个’index‘的值,这个值与tabbar中的pagePath是对应的,以此来判断该跳转哪个页面

<template>
	<Tabbar cureentPage='index'></Tabbar>
</template>

myinfo.vue

<script setup>
    import Tabbar from '@/common/tabbar/tabbar.vue'
</script>
<template>
 <Tabbar cureentPage='myinfo'></Tabbar>
</template>

 现在可以用了

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
uniapp中设置自定义tabbar可以通过修改配置文件来实现。首先,你可以在配置文件中添加一个midButton字段来控制是否显示中间按钮凸起的效果。接下来,你可以配置tabs字段来定义每个tab的图标、文本等属性。你还可以通过配置或者动态修改tab obj中的show属性来动态显示或隐藏某个tab。例如,你可以将第一个tab的show属性设置为false来隐藏它。此外,你还可以使用mark属性来设置角标数量,并决定是否显示角标。在每个导航页的onShow生命周期中使用uni.hideTabBar({animation: false})可以解决切换时出现原生tabBar的问题。这样,就可以实现自定义tabbar效果了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [uniapp自定义tabbar(支持中间凸起,角标,动态隐藏tab,全端适用)](https://blog.csdn.net/abs625/article/details/129496348)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [uniapp小程序自定义tabBar,根据身份切换自定义tabBar](https://blog.csdn.net/weixin_59803648/article/details/127203398)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值