uniapp小程序自定义导航栏

效果图如下

<template>
	<view class="content">
		<view class="main">
			<page1 v-if="tabbarIndex == 0"></page1>
			<page2 v-if="tabbarIndex == 1">
			</page2>
			<page3 v-if="tabbarIndex == 3"></page3>
			<page4 v-if="tabbarIndex == 4"></page4>
		</view>
		<!-- tabbar底部导航栏 -->
		<view class="tabbar-contaniner">
			<view class="tabbar-item" v-for="(item, index) in list" :key="index">
				<view v-if="index != 2" class="tab-item" @click="tabbarChange(item.path, index)">
					<image class="tab-img" :src="current == index ? item.iconPath : item.icon"></image>
					<text :class="{ tabTitle: true, select: current == index }">{
  
  { item.text }}</text>
				</view>
				<!-- 中间小圆球 -->
				<view v-else class="tab-mid" >
					<view class="txt1">+</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import page1 from '../page1/page1.vue'
	import page2 from '../page2/page2.vue'
	import page3 from '../page3/page3.vue'
	import page4 from '../page4/page4.vue' 
	export default {
		data() {
			return {
				title: 'Hello',
				current:0,//底部tabbar
				tabbarIndex:0,//页面的显示
				list: [{
						text: "首页",
						icon: "/static/shouye.png", //未选中图标
						iconPath: "/static/s-shouye.png", //选中图标
						path: "/pages/page1" //页面路径
					},
					{
						text: "运动",
						icon: "/static/sport.png", //未选中图标
						iconPath: "/static/s-sport.png", //选中图标
						path: "/pages/page2" //页面路径
					},
					{
				
					},//中间空闲位置
				
					{
						text: "消息",
						icon: "/static/msg.png", //未选中图标
						iconPath: "/static/s-msg.png", //选中图标
						path:"/pages/page3" //页面路径
					},
					{
						text: "我的",
						icon: "/static/my.png", //未选中图标
						iconPath: "/static/s-my.png", //选中图标
						path: "/pages/page4" //页面路径
					},
				],
			}
		},
		components:{
			page1,
			page2,
			page3,
			page4
		},
		onLoad() {

		},
		methods: {
tabbarChange(path, index) {
				this.current = index;
				this.tabbarIndex = index;

			},
		}
	}
</script>

<style lang="scss" scoped>
	.tabbar-contaniner {
		height: 120rpx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-evenly;
		position: absolute;
		position: fixed;
		bottom: -4rpx;
		left: 0;
		z-index: 40;
		background: url("/static/tabbarimg.png") no-repeat -49rpx center;
		background-size: 847rpx;
		background-color: transparent;

		& .tabbar-item:nth-child(3) {
			flex-shrink: 0;
			width: 120rpx;
		}

		// & .tabbar-item:nth-child(2) {
		// 	margin-left: 35rpx;
		// }
	}
	
	.tab-item {
		display: flex;
		flex-direction: column;
		font-size: 20rpx;
		color: #828282;
		align-items: center;
		justify-content: center;
	
		& .tab-img:first-child {
			width: 46rpx;
			height: 46rpx;
		}
	}
	.tab-img {
		width: 56rpx;
		height: 56rpx;
		margin-bottom: 10rpx;
	}
	
	.select {
		color: #fd8dc4;
	}
	
	.tabbar-item {
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 14rpx;
		width: 88rpx;
	}
	
	
	// 中间
	.tab-mid {
		background: #fd8dc4;
		width: 110rpx;
		height: 110rpx;
		border-radius: 50%;
		position: relative;
		top: -39px;
		z-index: 20;
		font-size: 60rpx;
		// color: #a060ff;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.txt1{
		color: #fff;
		font-size: 70rpx;
		line-height: 0;
		padding-bottom: 10rpx;
	}
</style>

所涉及到的页面。图片的话,自己去iconfont上面下载iconfont-阿里巴巴矢量图标库

底部导航栏的背景图:记得保存哦~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喜崽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值