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

uniapp微信小程序vue3自定义tabbar

在App.vue隐藏原生tabbar,也可以在pages.json中配置

在这里插入图片描述
在这里插入图片描述
二选一就好了

创建 CustomTabBar 公共组件

<template><view class="custom-tab-bar" :style="{paddingBottom: safeAreaHeight + 'px'}"><view class="tab-bar-item" :class="{'active' : props.currentPage === index}" v-for="(item, index) in tabBarList" :key="index"><image v-if="props.currentPage === index" :src="'../' + item.selectedIconPath" @click.stop="switchTab(item)"></image><image v-else :src="'../' + item.iconPath" @click.stop="switchTab(item)"></image><text>{{ item.text }}</text></view></view>
</template><script setup>
import { ref, onMounted } from 'vue';const props = defineProps({currentPage: Number,
})const tabBarList = ref([{pagePath: "pages/tabbar/msg",iconPath: "static/tabbar/dynamic.png",selectedIconPath: "static/tabbar/dynamic1.png",text: "动态"},{pagePath: "pages/tabbar/static",iconPath: "static/tabbar/statistic.png",selectedIconPath: "static/tabbar/statistic1.png",text: "统计"},{pagePath: "pages/tabbar/work",iconPath: "static/tabbar/work.png",selectedIconPath: "static/tabbar/work1.png",text: "工作台"},{pagePath: "pages/tabbar/find",iconPath: "static/tabbar/find.png",selectedIconPath: "static/tabbar/find1.png",text: "发现"},{pagePath: "pages/tabbar/user",iconPath: "static/tabbar/my.png",selectedIconPath: "static/tabbar/my1.png",text: "我的"}
]);// 切换 tab 的方法
const switchTab = (item) => {uni.switchTab({url: '/' + item.pagePath,})
};let safeAreaHeight = ref(0);onMounted(() => {// 获取底部安全区域高度uni.getSystemInfo({success: (res) => {let sHeight = res.screenHeight; // 获取屏幕高度let sTop = res.safeArea.bottom; // 获取安全区域底部高度safeAreaHeight.value = sHeight - sTop; // 计算安全区域距离底部的高度console.log('底部安全区域高度:', safeAreaHeight.value);}});uni.hideTabBar();
});
</script><style lang="scss" scoped>
.custom-tab-bar {position: fixed;z-index: 99;bottom: 0;left: 0;right: 0;display: flex;background-color: #ffffff;border-top: 1px solid #eeeeee;padding: 5px 0;
}.tab-bar-item {flex: 1;display: flex;flex-direction: column;align-items: center;justify-content: center;color: #93A2B7;&.active {color: #24C597;}&:nth-child(3) image {margin-top: -18px;width: 80rpx;height: 80rpx;}
}.tab-bar-item image {width: 24px;height: 24px;
}.tab-bar-item text {font-size: 12px;margin-top: 6rpx;
}
</style>

在每个tabbar页面中引入组件

在这里插入图片描述

http://www.lryc.cn/news/548008.html

相关文章:

  • BUUCTF——[GYCTF2020]FlaskApp1 SSTI模板注入/PIN学习
  • 如何用Kimi生成PPT?秒出PPT更高效!
  • 数据结构(回顾)
  • 全国产!瑞芯微3562Mini(2GHz四核A53 NPU)工业开发板规格书
  • 鸿蒙HarmonyOS评论功能小demo
  • 异常(6)
  • 精选一百道备赛蓝桥杯——2.K倍区间
  • 编译Telegram Desktop
  • 玩转python: 掌握Python数据结构之链表
  • upload-labs详解(1-12)文件上传分析
  • RAG系统(检索增强生成)的优化策略
  • 写毕业论文用哪个AI好?这6款AIGC论文工具给你答案
  • loadingcache优化
  • 【Vue3 Element UI - Plus + Tyscript 实现Tags标签输入及回显】
  • STM32 子设备通过CAN发送数据到主设备
  • Python可视化——地理空间型图表(自用)
  • WordPress报502错误问题解决-php-fpm-84.service loaded failed failed LSB: starts php-fpm
  • Python在SEO中的自动化应用爬虫开发与日志分析实例
  • thingsboard edge 在windows 环境下的配置
  • nnMamba:基于状态空间模型的3D生物医学图像分割、分类和地标检测
  • nginx 配置403页面(已亲测)
  • SyntaxError: Invalid or unexpected token in JSON at position x
  • Uncaught TypeError: Cannot read properties of undefined (reading ‘xxx‘)
  • Nginx 跨域配置详细讲解
  • 前端开发基石:HTML语义化深度解析与实践指南
  • mongodb安装教程以及mongodb的使用
  • C# 中的多线程同步机制:lock、Monitor 和 Mutex 用法详解
  • 【通义万相】蓝耘智算 | 开源视频生成新纪元:通义万相2.1模型部署与测评
  • 期权帮|中证1000股指期权交割结算价怎么算?
  • Python 面向对象高级编程-定制类