uniapp 自定义无图标tabbar

456

1.创建components组件,在tabbar页面引入该组件,附代码

<template>
	<view class="tab-bar">
		<view v-for="(item,index) in list" :key="index" :class="select === index? 'select' : 'tab-bar-item'"  @click="switchTab(item, index)">
			<view class="tab_text">{{item.text}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:['select'],
		data() {
			return {
				activeclass: 0,
				color: "#333333",
				selectedColor: "#333333",
				list: [{
					text: "首页"
				}, {
					text: "盆底肌健康科普"
				}, {
					text: "信息管理"
				}],
				switchPages:['../../pages/home/home','../../pages/healthy/healthy','../../pages/information/information']
			}
		},
		methods: {
			switchTab(item, index) {
				uni.switchTab({
					url: this.switchPages[index]
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.tab-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 100rpx;
		background: white;
		display: flex;
		justify-content: center;
		align-items: center;
		padding-bottom: env(safe-area-inset-bottom); 
		.select {
			height: 100%;
			flex: 1;
			text-align: center;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			background-color: #00cc99;
			.tab_img {
				width: 37rpx;
				height: 41rpx;
			}
			.tab_text {
				font-size: 28rpx;
				margin-top: 9rpx;
			}
		}
		.tab-bar-item {
			height: 100%;
			flex: 1;
			text-align: center;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			.tab_img {
				width: 37rpx;
				height: 41rpx;
			}
			.tab_text {
				font-size: 28rpx;
				margin-top: 9rpx;
			}
		}
	}
</style>

2.父组件引入时传入activeclass值为该页面的序号,使之实现点击更改class样式

<template>
	<tab-bar :select="activeclass"></tab-bar>
</template>
<script>
	import tabBar from '@/components/tabBar/tabBar.vue'
	export default {
		components:{
			tabBar
		},
		data(){
			return{
				activeclass: 1
			}
		}
	}
</script>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值