uni-app 自定义tabbar

uni-app 自定义tabbar

第一步:在components下创建目录tabbar,再在tabbar目录下创建tabbar.vue文件

复制代码
<template>
	<view class="tabbar jsf-around">
		<view class="tabbar-item dis-c align-center " v-for="(item,index) in list" :key="index" @click="changeTab(index)">

			<view class="dis-c align-center " v-if="current == index">
				<view class="xian"></view>
				<view class="dis-c align-center padding-tb-20">
					<image :style="{width:item.width, height:item.height}" :src="item.selectedIconPath"></image>
					<view class="text active font-pf-b margin-t-5">{{item.text}}</view>
				</view>
			</view>

			<view v-else>
				<view class="wu_xian"></view>
				<view class="dis-c align-center padding-tb-20">
					<image :style="{width:item.width, height:item.height}" :src="item.iconPath"></image>
					<view class="text font-pf-b margin-t-5">{{item.text}}</view>
				</view>
			</view>

			<!-- <image class="img" :src="item.selectedIconPath" v-if="current == index"></image>
			<image class="img" :src="item.iconPath" v-else></image>
			<view class="text active font-pf-b " v-if="current == index">{{item.text}}</view>
			<view class="text font-pf-b " v-else>{{item.text}}</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		name: "tabbar",
		props: {
			current: String
		},
		created() {
			uni.hideTabBar()
		},
		data() {
			return {
				list: [{
						pagePath: "pages/index/index",
						iconPath: "../../static/tabbar/shouye.png",
						selectedIconPath: "../../static/tabbar/shouye(lan).png",
						text: "首页",
						width: '48rpx',
						height: '51rpx',
					}, {
						pagePath: "pages/tongji/tongji",
						iconPath: "../../static/tabbar/tongji.png",
						selectedIconPath: "../../static/tabbar/tongji(lan).png",
						text: "统计",
						width: '47rpx',
						height: '51rpx',
					},
					{
						pagePath: "pages/xiaoxi/xiaoxi",
						iconPath: "../../static/tabbar/xiaoxi.png",
						selectedIconPath: "../../static/tabbar/xiaoxi(lan).png",
						text: "消息",
						width: '51rpx',
						height: '51rpx',
					},
					{
						pagePath: "pages/wode/wode",
						iconPath: "../../static/tabbar/wode.png",
						selectedIconPath: "../../static/tabbar/wode(lan).png",
						text: "我的",
						width: '44rpx',
						height: '51rpx'
					}
				]
			}
		},
		methods: {
			changeTab(e) {
				// console.log(e);
				uni.switchTab({
					url: '/' + this.list[e].pagePath,
				})
			}
		}
	}
</script>

<style scoped>
	.tabbar {
		position: absolute;
		bottom: 0;
		z-index: 99;
		width: 100%;
		background: #FFFFFF;
		box-shadow: 0px -9px 49px 0px rgba(212, 221, 236, 0.47);
		border-radius: 60rpx 60rpx 0px 0px;
		background-repeat: no-repeat;
		/* padding: 0 0 20rpx 0; */
	}

	,
	.tabbar-item {}

	.wu_xian {
		width: 30rpx;
		height: 8rpx;
		background: #fff;
	}

	.xian {
		width: 30rpx;
		height: 8rpx;
		background: #1C65F3;
	}

	/* .img {
		width: 45upx;
		height: 48upx;
	} */

	.text {
		font-size: 24upx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #bbb;
		/* line-height: 27upx; */
	}

	.text.active {
		color: #1061F5;
	}
</style>

第二步:在page下创建index目录,创建index.vue文件,调用自定义组件tabbar

复制代码
<template>
	<view>
		<tabbar current="0"></tabbar>
		</view>
</template>
<script>
	import tabbar from '@/components/tabbar/tabbar'  //引用组件中的tabbar
	export default {
		components: {
			tabbar	//引用组件中的tabbar
		},
		data() {
			return {
			}
		},

		created() {
			uni.hideTabBar()  //隐藏掉原生tabbar组件
		},
		methods: {
		}
	}
</script>
相关推荐
疯狂的沙粒1 小时前
在uni-app中如何从Options API迁移到Composition API?
javascript·vue.js·uni-app
anyup5 小时前
快崩溃了!华为应用商店已经 4 次驳回我的应用上线
前端·华为·uni-app
alphaair12 小时前
【一步步开发AI运动APP】十、微调优化内置运动分析器,灵活适配不同的应用场景
uni-app·ai运动·ai运动识别·ai健身·ai体测·ai运动app·ai运动检测·工会云上运动会·ai人体检测·ai姿态识别
moxiaoran575313 小时前
uni-app学习笔记二十三--交互反馈showToast用法
笔记·学习·uni-app
Angindem1 天前
从零搭建uniapp项目
前端·vue.js·uni-app
Bug从此不上门1 天前
【无标题】
前端·javascript·uni-app·vue
耶啵奶膘1 天前
uniapp+vue2解构赋值和直接赋值的优缺点
uni-app
疯狂的沙粒1 天前
uni-app 项目支持 vue 3.0 详解及版本升级方案?
前端·vue.js·uni-app
Jiaberrr1 天前
uniapp Vue2 获取电量的独家方法:绕过官方插件限制
前端·javascript·uni-app·plus·电量
^Rocky1 天前
uniapp 对接腾讯云IM群公告功能
uni-app·腾讯云