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>
相关推荐
耶啵奶膘14 小时前
uni-app头像叠加显示
开发语言·javascript·uni-app
chéng ௹14 小时前
uniapp 封装uni.showToast提示
前端·javascript·uni-app
吴传逞15 小时前
记一次uniapp+nutui-uniapp搭建项目
uni-app
雪芽蓝域zzs17 小时前
uni-app倒计时公共组件 封装,倒计时组件
uni-app
2501_9159184120 小时前
iOS 开发全流程实战 基于 uni-app 的 iOS 应用开发、打包、测试与上架流程详解
android·ios·小程序·https·uni-app·iphone·webview
黑马源码库miui5208620 小时前
JAVA同城打车小程序APP打车顺风车滴滴车跑腿源码微信小程序打车源码
java·微信·微信小程序·小程序·uni-app
清风细雨_林木木1 天前
uni-app 和 uni-app x 的区别
uni-app
iOS阿玮1 天前
期待iOS开发者加入,共同抵制“苹果税”反垄断招募令!
uni-app·app·apple
普通网友1 天前
支持二次开发的代练App源码:订单管理、代练监控、安全护航功能齐全,一站式解决代练护航平台源码(PHP+ Uni-app)
安全·uni-app·php
蜕变菜鸟1 天前
uview使用u-popup组件当开启遮罩层禁止下层页面滚动。uniapp弹框禁止页面上下滚动。
uni-app