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>
相关推荐
工业互联网专业9 分钟前
毕业设计选题:基于springboot+vue+uniapp的驾校报名小程序
vue.js·spring boot·小程序·uni-app·毕业设计·源码·课程设计
&白帝&8 小时前
uniapp中使用picker-view选择时间
前端·uni-app
fakaifa8 小时前
八戒农场小程序V2最新源码
小程序·uni-app·php·生活·开源软件
平凡シンプル12 小时前
安卓 uniapp跨端开发
android·uni-app
艾小逗14 小时前
uniapp快速入门教程,内容来源于官方文档,仅仅记录快速入门需要了解到的知识点
小程序·uni-app·app·es6
鸭子嘎鹅子呱1 天前
uniapp使用高德地图设置marker标记点,后续根据接口数据改变某个marker标记点,动态更新
uni-app·map·高德地图
计算机源码社1 天前
分享一个基于微信小程序的居家养老服务小程序 养老服务预约安卓app uniapp(源码、调试、LW、开题、PPT)
android·微信小程序·uni-app·毕业设计项目·毕业设计源码·计算机课程设计·计算机毕业设计开题
Angus-zoe2 天前
uniapp+vue+微信小程序实现侧边导航
vue.js·微信小程序·uni-app
Pluto & Ethereal2 天前
uni-app尺寸单位、flex布局于背景图片
uni-app
天空下sky2 天前
uniapp+若依 开发租房小程序源码分享
uni-app