当前位置: 首页 > article >正文

uniapp对tabbar封装,简单好用

第一种,效果展示

上代码,新建一个公用组件,tabbar.vue

<template>
	<view class="tabbar">
		<view class="tabbar-item" @click="tabbarbtn(0)">
			<image class="item-image" v-if="value==0"  src="@/static/icon1.png" image>
			<image class="item-image" v-else src="@/static/icon5.png" ></image>
			<text :class="['item-text',value==0?'active':'']">微信</text>
		</view>
		<view class="tabbar-item" @click="tabbarbtn(1)">
			<image class="item-image" v-if="value==1" src="@/static/icon2.png" mode=""></image>
			<image class="item-image" v-else src="@/static/icon6.png" mode=""></image>
			<text :class="['item-text',value==1?'active':'']">通讯录</text>
		</view>
		<!-- 购物车没有数量情况 -->
		<!-- <view class="tabbar-item" @click="tabbarbtn(2)">
			<image class="item-image" v-if="value==2"  src="@/static/icon3.png" mode=""></image>
			<image class="item-image" v-else src="@/static/icon7.png" mode=""></image>
			<text :class="['item-text',value==2?'active':'']">发现</text>
		</view> -->
		<!-- 购物车有数量情况 -->
		<view class="tabbar-item" @click="tabbarbtn(2)">
			<view class="item-view">
				<image class="item-image" v-if="value==2"  src="@/static/icon3.png" mode=""></image>
				<image class="item-image" v-else src="@/static/icon7.png" mode=""></image>
				<view class="item-num">
					{{num}}
				</view>
			</view>
			<text :class="['item-text',value==2?'active':'']">发现</text>
		</view>
		<view class="tabbar-item" @click="tabbarbtn(3)">
			<image class="item-image" v-if="value==3"  src="@/static/icon4.png" mode=""></image>
			<image class="item-image" v-else   src="@/static/icon8.png" mode=""></image>
			<text :class="['item-text',value==3?'active':'']">我的</text>
		</view>
	</view>
</template>

<script>
	export default {
		name: "tabbar",
		data() {
			return {
				num:2,
				value:this.vlue,
				 list: [{
				 		path: "pages/index/home"
				 	},
				 	{
				 		path: "pages/index/login"
				 	},
				 	{
				 		path: "pages/index/cartpage"
				 	},
				 	{
				 		path: "pages/index/personage"
				 	},
				 ],
			};
		},
		props:{
			vlue:{
				type: Number,
			}
		},
		methods:{
			tabbarbtn(index){
				uni.switchTab({
					url: '/' + this.list[index].path,
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tabbar {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		// 苹果手机下边有小黑条的安全距离
		padding-bottom: env(safe-area-inset-bottom);
		background-color: #fff;
		box-shadow: 0rpx 4rpx 10rpx 0rpx rgba(0,0,0,0.1);
		display: flex;
		align-items: center;
		
		

		.tabbar-item {
			padding:35rpx 0 15rpx;
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			.item-view{
				position: relative;
				.item-num{
					position: absolute;
					right:-85%;
					top:-40%;
					font-size:20rpx;
					color: #fff;
					border-radius: 20rpx;
					padding: 5rpx 15rpx;
					background-color: red;
				}
			}
			.item-image{
				display: block;
				width: 50rpx;
				height: 50rpx;
			}
			.item-text{
				margin-top: 4rpx;
				font-size: 24rpx;
				color: #666666;
			}
			.active{
				color: #d81e06;
			}
		}
	}
</style>

在pages.json中要tabbar里的页面路径

使用方式,在其他tabbar页面,引入此文件使用即可。


http://www.kler.cn/news/302870.html

相关文章:

  • Unity3d中制作触发区域为圆形的按钮
  • YOLOv5-6.x源码分析----数据集创建之dataloaders.py
  • 【Python 千题 —— 算法篇】寻找最长回文子串
  • JavaWeb【day11】--(SpringBootWeb案例)
  • Android APK插件化:DynamicAPK技术如何改变游戏规则
  • linux安装redis、使用redis、用springboot连接redis
  • DataWind将string类型转化为int类型的报错解决
  • 全国智能网联招标项目一周速览(2024年9月13日)
  • leetcode练习 子集
  • HTML中的零宽字符
  • C# 异步编程中的 SynchronizationContext:掌握上下文同步的艺术
  • 源码编译llama.cpp 、ggml 后端启用自定义BLAS加速
  • 【STM32】独立看门狗(IWDG)原理详解及编程实践(上)
  • [网络][CISCO]CISCO IOS升级
  • 走进低代码表单开发(一):可视化表单数据源设计
  • Redis 入门 - C#|.NET Core客户端库六种选择
  • C++ | Leetcode C++题解之第389题找不同
  • 说真心话,在IT行业,项目经理不懂「敏捷管理」真混不下去!
  • 就服务器而言,ARM架构与X86架构有什么区别?各自的优势在哪里?
  • EP10 全局渐变背景色
  • Android Jetpact Lifecycle 解析
  • STM32双轮平衡小车(基于STM32F103C8T6HAL库)
  • [Go]-抢购类业务方案
  • 设计模式 解释器模式(Interpreter Pattern)
  • 从键入网址到显示页面全流程(超详细版)
  • Axure中继器介绍
  • 大屏可视化适配方案
  • 前端数组迭代方法分析
  • 【深度学习】多层感知机的从零开始实现与简洁实现
  • 【RabbitMQ】概述