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>
相关推荐
林涧泣8 小时前
【Uniapp-Vue3】开发userStore用户所需的相关操作
前端·vue.js·uni-app
css趣多多12 小时前
使用git管理uniapp项目
uni-app
前端小雪的博客.1 天前
Uniapp 小程序复制、粘贴功能实现
小程序·uni-app
竣子好逑1 天前
uniapp v2 组件
前端·uni-app
筱歌儿1 天前
uniapp 阿里云点播 播放bug
uni-app·bug
陆康永1 天前
uniapp-X 对象动态取值
uni-app
林涧泣1 天前
【Uniapp-Vue3】登录成功后获取当前用户信息并渲染到页面中
前端·javascript·uni-app
前端小雪的博客.1 天前
Uniapp 小程序接口封装与使用
微信小程序·uni-app
离别又见离别1 天前
uniapp 本地数据库多端适配实例(根据运行环境自动选择适配器)
数据库·vue.js·sqlite·uni-app·db
香菜的开发日记1 天前
uniapp 系统学习,从入门到实战(四)—— 页面与路由管理
uni-app