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

uni-app 实现凸起的 tabbar 底部导航栏

效果图

在 pages.json 中设置隐藏自带的 tabbar 导航栏

"custom": true, // 开启自定义tabBar(不填每次原来的tabbar在重新加载时都回闪现)

新建一个 custom-tabbar.vue 自定义组件页面

custom-tabbar.vue
<!-- 自定义底部导航栏 -->
<template><view class="container"><viewclass="tabbar-item":class="[item.centerItem ? ' center-item' : '']":style="'width: calc(100% /' + tabbarList.length + ')'"@click="changeItem(item)"v-for="(item, i) in tabbarList":key="i"><view class="item-top"><image :src="curItem === item.id ? item.selectedIconPath : item.iconPath" /></view><view class="item-bottom" :class="[curItem === item.id ? 'item-active' : '']">{{ item.text }}</view></view></view>
</template><script>
export default {props: {/* 当前导航栏 */currPage: {type: Number,default: 0}},data() {return {curItem: 0, // 当前所选导航栏tabbarList: [{id: 0,pagePath: "/pages/public/index",iconPath: "/static/tab-bar/home.png",selectedIconPath: "/static/tab-bar/home-active.png",text: "首页",centerItem: false},{id: 1,pagePath: "",iconPath: "/static/tab-bar/bulge-active.png",selectedIconPath: "/static/tab-bar/bulge-active.png",text: "称重",centerItem: true},{id: 2,pagePath: "/pages/weight/my",iconPath: "/static/tab-bar/my.png",selectedIconPath: "/static/tab-bar/my-active.png",text: "我的",centerItem: false}] // 导航栏列表};},mounted() {this.curItem = this.currPage; // 当前所选导航栏// #ifdef H5uni.hideTabBar(); // 隐藏 tabBar 导航栏// #endif},methods: {/* 导航栏切换 */changeItem(e) {// 中间凸起按钮if (e.id === 1) {// todoreturn;}uni.switchTab({ url: e.pagePath }); // 跳转到其他 tab 页面}}
};
</script><style lang="scss" scoped>
$textDefaultColor: #999; // 文字默认颜色
$bottomBg: #fff; // 底部背景
$textSelectedColor: #67c23a; // 文字选中颜色
$centerItemBg: #fff; // 中间凸起按钮背景
.container {position: fixed;bottom: 0;left: 0;display: flex;align-items: center;width: 100%;height: 110rpx;color: $textDefaultColor;padding: 5rpx 0;background-color: $bottomBg;box-shadow: 0 0 10rpx #999;
}
.tabbar-item {display: flex;flex-direction: column;justify-content: center;align-items: center;text-align: center;height: 100rpx;.item-top {flex-shrink: 0;width: 65rpx;height: 65rpx;padding: 4rpx;image {width: 100%;height: 100%;}}.item-bottom {width: 100%;font-size: 28rpx;}.item-active {color: $textSelectedColor;}
}
.center-item {position: relative;.item-top {position: absolute;top: -55rpx;left: 50%;transform: translateX(-50%);width: 105rpx;height: 105rpx;background-color: $centerItemBg;border-radius: 50%;}.item-bottom {position: absolute;bottom: 5rpx;}
}
</style>

底部安全区域的适配问题可查看:uni-app 苹果手机底部安全区域的适配问题

在 main.js 中引用组件

// 注册全局组件
import customTabbar from "components/custom-tabbar.vue"
Vue.component('custom-tabbar', customTabbar)

在要用到的页面中直接调用

<!-- 自定义 tabbar 底部导航栏 -->
<custom-tabbar :curr-page="0" />
http://www.lryc.cn/news/180261.html

相关文章:

  • 中国1km土壤特征数据集(2010年)
  • 计算机网络笔记 第二章 物理层
  • 使用CreateProcess崩溃:处未处理的异常: 0xC0000005: 写入位置 0x00415652 时发生访问冲突
  • Java 华为真题-出租车计费
  • 开源layui前端框架 收款码生成系统源码 多合一收款码生成源码 带50多套UI模板
  • 微服务moleculer01
  • C++中将指针传递给函数
  • 【51单片机编写占空比按秒渐亮与渐暗】2023-10-2
  • OCI 发布了容器运行时和镜像规范!
  • C++学习笔记一: 变量和基本类型
  • 探索ClickHouse——同时支持导入导出功能的文件格式
  • Scipy库提供了多种正态性检验和假设检验方法
  • 去雨去雪去雾算法之本地与服务器的TensorBoard使用教程
  • 【小沐学前端】Node.js实现基于Protobuf协议的WebSocket通信
  • MySQL学习笔记24
  • objective-c 基础学习
  • 【精彩回顾】 用sCrypt在Bitcoin上构建智能合约
  • Kotlin 使用泛型
  • 深度学习 二:COVID 19 Cases Prediction (Regression)
  • UG\NX二次开发 信息窗口的4种输出方式 NXOpen::ListingWindow::DeviceType
  • mavn打包时如何把外部依赖加进去?
  • 爬虫代理请求转换selenium添加带有账密的socks5代理
  • Redis 如何实现数据不丢失的?
  • [高等数学]同济版高等数学【第七版】上下册教材+习题全解PDF
  • 【面试题精讲】Java超过long类型的数据如何表示
  • Shapiro-Wilk正态性检验(Shapiro和Wilk于1965年提出)
  • debian设置允许ssh连接
  • 【C语言经典100例题-66】(用指针解决)输入3个数a,b,c,按大小顺序输出。
  • 【STM32 CubeMX】移植u8g2(一次成功)
  • 华为云智能化组装式交付方案 ——金融级PaaS业务洞察及Web3实践的卓越贡献