uniapp-微信小程序自定义底部

最近项目遇到需要自定义底部tabbar的,本来随手写了个组件丢给前端,没想到出现了跳转页面闪一下的情况。于是我决定重构一下。
大体思路就是把tabbar写在首页,4个tabbar页面写成组件。

页面-首页直接写tabbar

首页:

<template>
	<view>
		<view class="tabbar">
			<!-- 组件1 -->
			<view class="tab-item" @click="active(0)">
				<image class="tab-img" src="/static/images/index_default.png" v-if="activecount != 0"></image>
				<image class="tab-img" src="/static/images/index_active.png" v-if="activecount == 0"></image>
				<view class="tab-word" :class="activecount == 0?'tab-active':''">
					首页
				</view>
			</view>
			<!-- 组件2 -->
			<view class="tab-item" @click="active(1)">
				<image class="tab-img" src="/static/images/filter_default.png" v-if="activecount != 1"></image>
				<image class="tab-img" src="/static/images/filter_active.png" v-if="activecount == 1"></image>
				<view class="tab-word" :class="activecount == 1?'tab-active':''">
					档案
				</view>
			</view>
			<!-- 中间的+号页面 -->
			<view class="tab-item" @click="active(2)">
				<image class="tab-img publishFill" src="/static/images/publish.png" v-if="activecount != 2"></image>
				<image class="tab-img publishFill" src="/static/images/publish.png" v-if="activecount == 2"></image>
			</view>

			<!-- 组件3 -->
			<view class="tab-item" @click="active(3)">
				<image class="tab-img" src="/static/images/mind_defalut.png" v-if="activecount != 3"></image>
				<image class="tab-img" src="/static/images/mind_active.png" v-if="activecount == 3"></image>
				<view class="tab-word" :class="activecount == 3?'tab-active':''">
					能力
				</view>
			</view>
			<!-- 组件4 -->
			<view class="tab-item" @click="active(4)">
				<image class="tab-img" src="/static/images/my_defalut.png" v-if="activecount != 4"></image>
				<image class="tab-img" src="/static/images/my_active.png" v-if="activecount == 4"></image>
				<view class="tab-word" :class="activecount == 4?'tab-active':''">
					我的
				</view>
			</view>
		</view>
		<index v-if="activecount === 0"></index>
		<archives  v-if="activecount === 1"></archives>
		<mind  v-if="activecount === 3"></mind>
		<mycenter v-if="activecount === 4"></mycenter>
	</view>
</template>
<script>
	import index from '../../../components/index/index.vue';
	import archives from '../../../components/archives/archives.vue';
	import mind from '../../../components/mind/mind.vue';
	import mycenter from '../../../components/mycenter/mycenter.vue';
	export default {
		data() {
			return {
				activecount: 0
			};
		},
		methods: {
			sendArtId(artId){
				this.getcommentArdId = artId;
			},
			active(num) {
				if (num == 2) {
					uni.navigateTo({
						url: "/teaArchive/pages/publish/publish"
					})
				} else {
					this.activecount = num;
				}
			}
		},
		components: {
			index,
			archives,
			mind,
			mycenter,
		}
	}
</script>

<style>
	.tabbar {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		height: 130rpx;
		background-color: #FFFFFF;
		display: flex;
		justify-content: space-between;
		padding: 16rpx 46rpx;
		box-shadow: 0px -4px 12px 0px rgba(0, 0, 0, 0.06);
		z-index: 999999;
	}

	.tab-item {
		text-align: center;
	}

	.tab-item .tab-img {
		width: 52rpx;
		height: 52rpx;
	}

	.tab-word {
		font-size: 20rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #7A887D;
		line-height: 20rpx;
	}

	.tab-active {
		color: #338A5F !important;
	}

	.bage {
		width: 32rpx;
		height: 32rpx;
		background-color: rgba(255, 105, 91, 1);
		color: #FFFFFF;
		border-radius: 50%;
		line-height: 30rpx;
		position: absolute;
		top: 16rpx;
		margin-left: 16rpx;
	}

	.publishFill {
		width: 112rpx !important;
		height: 112rpx !important;
		background: #338A5F;
		border-radius: 112rpx;
		margin-top: -40rpx;
	}
</style>

4个组件就是普通的vue组件,这里就不写了。
组件里上拉加载,页面触底等操作就uniapp的 scroll-view 就能完美解决问题,散会。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

土拔鼠旱懒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值