uniapp对tabbar封装,简单好用

embedded/2024/9/23 9:06:49/

第一种,效果展示

上代码,新建一个公用组件,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.ppmy.cn/embedded/111329.html

相关文章

什么是 TDengine?

TDengine 是一款专为物联网、工业互联网等场景设计并优化的大数据平台&#xff0c;其核心模块是高性能、集群开源、云原生、极简的时序数据库。它能安全高效地将大量设备、数据采集器每天产生的高达 TB 甚至 PB 级的数据进行汇聚、存储、分析和分发&#xff0c;对业务运行状态进…

嵌入式软件--51单片机 DAY 3

一、独立按键 按键的作用相当于一个开关&#xff0c;按下时接通&#xff08;或断开&#xff09;&#xff0c;松开后断开&#xff08;或接通&#xff09;。 &#xff08;1&#xff09;需求 通过SW1、SW2、SW3、SW4四个独立按键分别控制LED1、LED2、LED3、LED4的亮灭&#xff0…

ETCD的备份和恢复

一、引言 ETCD是一个高度可用的键值存储系统&#xff0c;被广泛应用于Kubernetes等分布式系统中以存储关键配置数据和服务发现信息。由于ETCD的重要性&#xff0c;确保其数据的安全性和可靠性至关重要。本文将介绍ETCD备份与恢复的基础知识、常用方法及最佳实践。 二、概述 …

力扣9.7

115.不同的子序列 题目 给你两个字符串 s 和 t &#xff0c;统计并返回在 s 的 子序列 中 t 出现的个数&#xff0c;结果需要对 109 7 取模。 数据范围 1 < s.length, t.length < 1000s 和 t 由英文字母组成 分析 令dp[i][j]为s的前i个字符构成的子序列中为t的前j…

后端开发刷题 | 兑换零钱(动态规划)

描述 给定数组arr&#xff0c;arr中所有的值都为正整数且不重复。每个值代表一种面值的货币&#xff0c;每种面值的货币可以使用任意张&#xff0c;再给定一个aim&#xff0c;代表要找的钱数&#xff0c;求组成aim的最少货币数。 如果无解&#xff0c;请返回-1. 数据范围&am…

PHP一键约课高效健身智能健身管理系统小程序源码

一键约课&#xff0c;高效健身 —— 智能健身管理系统让健康触手可及 &#x1f3cb;️‍♀️ 告别繁琐&#xff0c;一键开启健身之旅 你还在为每次去健身房前的繁琐预约流程而烦恼吗&#xff1f;现在有了“一键约课高效健身智能健身管理系统”&#xff0c;所有问题都迎刃而解…

HSmartWindowControl 滚轮缩放 交互式绘制ROI 可修改 存储

一直想达到这个效果,奈何智商简单;今天来做一下记录; 个人习惯 Winform 新建以后删除xxx.designer.cs再双击Form1.cs设计器;就会在该 文件下 自动生成InitializeComponent() 且可 由设计器生成的所有winform界面程序则会出现在InitializeComponent()里面; 这样的好处很多,所…

Leetcode面试经典150题-2.两数相加

解法都在代码里&#xff0c;不懂就留言或者私信 理论上提交这个就是最优解 字节考过不下20次&#xff0c;这个高居字节面试榜第9名 /*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode() {}* ListNode…