uniapp tababr凸出图标已经自定义tabbar

2023-10-13 05:30

本文主要是介绍uniapp tababr凸出图标已经自定义tabbar,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

uniapp关于tabbar的文档在这里插入图片描述

现在我想tabbar中间的显示为凸出的图标,类似下图

在这里插入图片描述

  1. 只需要在app中使用,不用兼容小程序的话,可以使用官方的midButton配置项,该配置项不兼容各种小程序。
    在这里插入图片描述
"midButton": {"height": "70px", //修改距离底下的高度 "iconWidth": "50px", // 缩放图片大小 自己调整 "iconPath": "static/33cd2904c1d0e00cce947d9248eee4a.png","selectedIconPath": "static/5x471a3cb9de2330f0d7ee72547772bd7.png","text": "开单"
},
  1. 另一种方法,可以使用uniapp的组件,类于m-tabbar直接导入到项目中,进行使用,可以根据自身需求改变其中样式 【该组件,需请在page.json中tabbarde list添加全部tabbar】
<m-tabbar native :beforeChange="onBeforeChange"><template v-slot:tabbar_index_2><view class="custom_style"><view class="custom_style_icon">+</view><view class="custom_style_text">下单</view></view></template></m-tabbar>
methods: {onBeforeChange(next) {next()uni.showModal({title: '非法进入',content: '您正在非法进入其他页面,是否继续',success: function (res) {if (res.confirm) {next()} else if (res.cancel) {console.log('用户点击取消');}}// })}}

对应写上样式,根据需求进行修改路由守卫。可以将该组件进行重新封装。
封装代码如下:

<template name="zxd-tabbar"><view><m-tabbar native :beforeChange="onBeforeChange"><template v-slot:tabbar_index_2><view class="custom_style"><view class="custom_style_icon">+<!-- <image src="/static/bro_union_plus.png" mode=""></image> --></view><view class="custom_style_text">下单</view></view></template></m-tabbar></view>
</template><script>export default {data() {return {}},onLoad() {},methods: {onBeforeChange(next) {next()// uni.showModal({// 	title: '非法进入',// 	content: '您正在非法进入其他页面,是否继续',// 	success: function (res) {// 		if (res.confirm) {// 			next()// 		} else if (res.cancel) {// 			console.log('用户点击取消');// 		}// 	}// })}}}
</script><style lang="less" scoped>@ThemeColor: #3cc4e0;.custom_style {color: #aaa;display: flex;flex-direction: column;align-items: center;justify-content: center;font-size: 24upx;gap: 10upx;.custom_style_icon {background-color: @ThemeColor;color: #fff;font-size: 80rpx;width: 90upx;height: 90upx;border-radius: 100%;display: flex;justify-content: center;align-items: center;margin-top: -40upx;}.custom_style_text {// background-color: @ThemeColor;// font-size: 28rpx;// width: 120rpx;// height: 120rpx;border-radius: 100%;display: flex;justify-content: center;align-items: center;// margin-top: -40rpx;}}
</style>

在各个主页面最后进行引用该组件,进行使用

<zxd-tabbar></zxd-tabbar>
  1. 或者进行自定义组件【该组件在页面中进行引用,需计算tabbar的高度,尤其是含有列表滚动的页面】 封装组件如下:
<template><view class="tabbar-container"><block><view class="tabbar-item" v-for="(item, index) in tabbarList":class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)"><view class="item-top"><text v-if="item.centerItem">+</text><image :src="currentItem == item.id ? item.selectedIconPath : item.iconPath" v-else></image></view><view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']"><text>{{ item.text }}</text></view></view></block></view>
</template><script>export default {props: {currentPage: {type: Number,default: 0}},data() {return {currentItem: 0,tabbarList: [{id: 0,pagePath: "/pages/tabbar/order/order",iconPath: "/static/ic_order_in.png",selectedIconPath: "/static/ic_order_on.png",text: "我发的",centerItem: false},{id: 1,pagePath: "/pages/tabbar/received/received",iconPath: "/static/ic_received_in.png",selectedIconPath: "/static/ic_received_on.png",text: "我收的",centerItem: false},{id: 2,pagePath: "/pages/order/orderWrite/orderWrite",iconPath: "/static/ic_main_in.png",selectedIconPath: "/static/ic_main_on.png",text: "开单",centerItem: true},{id: 3,pagePath: "/pages/tabbar/news/news",iconPath: "/static/ic_news_in.png",selectedIconPath: "/static/ic_news_on.png",text: "新闻",centerItem: false},{id: 4,pagePath: "/pages/tabbar/main/main",iconPath: "/static/ic_main_in.png",selectedIconPath: "/static/ic_main_on.png",text: "我的",centerItem: false}]};},mounted() {this.currentItem = this.currentPage;uni.hideTabBar();},methods: {changeItem(item) {let _this = this;// console.log(item)if (item.id == 2) {  //通过不同的路径进行跳转,并没有把这个页面写在tarbar中uni.navigateTo({url: '/pages/order/orderWrite/orderWrite'})return}// _this.currentItem = item.id;uni.switchTab({url: item.pagePath});}}};
</script>
<style lang='less'>@ThemeColor: #3cc4e0;view {padding: 0;margin: 0;box-sizing: border-box;}.tabbar-container {position: fixed;bottom: 0;left: 0;width: 100%;height: 110rpx;box-shadow: 0 0 5px #999;display: flex;align-items: center;padding: 5rpx 0;color: #999999;}.tabbar-container .tabbar-item {width: 20%;height: 100rpx;display: flex;flex-direction: column;justify-content: center;align-items: center;text-align: center;}.tabbar-container .item-active {color: #3cc4e0;}.tabbar-container .center-item {display: block;position: relative;}.tabbar-container .tabbar-item .item-top {width: 70rpx;height: 70rpx;padding: 10rpx;}.tabbar-container .center-item .item-top {flex-shrink: 0;width: 100rpx;height: 100rpx;position: absolute;top: -50rpx;left: calc(50% - 50rpx);border-radius: 50%;box-shadow: 0 0 5px #999;background-color: #ffffff;display: flex;align-items: center;justify-content: center;}.tabbar-container .tabbar-item .item-top image {width: 100%;height: 100%;}.tabbar-container .tabbar-item .item-top text {color: #3cc4e0;font-size: 90upx;}.tabbar-container .tabbar-item .item-bottom {font-size: 28rpx;width: 100%;}.tabbar-container .center-item .item-bottom {position: absolute;bottom: 5rpx;}
</style>

在页面中使用如下,需要传对应的currentPage值,不然会出现点击闪烁的问题

<zxd-tabbar :currentPage='0'></zxd-tabbar>

这篇关于uniapp tababr凸出图标已经自定义tabbar的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/201088

相关文章

C#中通过Response.Headers设置自定义参数的代码示例

《C#中通过Response.Headers设置自定义参数的代码示例》:本文主要介绍C#中通过Response.Headers设置自定义响应头的方法,涵盖基础添加、安全校验、生产实践及调试技巧,强... 目录一、基础设置方法1. 直接添加自定义头2. 批量设置模式二、高级配置技巧1. 安全校验机制2. 类型

SpringBoot AspectJ切面配合自定义注解实现权限校验的示例详解

《SpringBootAspectJ切面配合自定义注解实现权限校验的示例详解》本文章介绍了如何通过创建自定义的权限校验注解,配合AspectJ切面拦截注解实现权限校验,本文结合实例代码给大家介绍的非... 目录1. 创建权限校验注解2. 创建ASPectJ切面拦截注解校验权限3. 用法示例A. 参考文章本文

Vite 打包目录结构自定义配置小结

《Vite打包目录结构自定义配置小结》在Vite工程开发中,默认打包后的dist目录资源常集中在asset目录下,不利于资源管理,本文基于Rollup配置原理,本文就来介绍一下通过Vite配置自定义... 目录一、实现原理二、具体配置步骤1. 基础配置文件2. 配置说明(1)js 资源分离(2)非 JS 资

聊聊springboot中如何自定义消息转换器

《聊聊springboot中如何自定义消息转换器》SpringBoot通过HttpMessageConverter处理HTTP数据转换,支持多种媒体类型,接下来通过本文给大家介绍springboot中... 目录核心接口springboot默认提供的转换器如何自定义消息转换器Spring Boot 中的消息

Python自定义异常的全面指南(入门到实践)

《Python自定义异常的全面指南(入门到实践)》想象你正在开发一个银行系统,用户转账时余额不足,如果直接抛出ValueError,调用方很难区分是金额格式错误还是余额不足,这正是Python自定义异... 目录引言:为什么需要自定义异常一、异常基础:先搞懂python的异常体系1.1 异常是什么?1.2

Linux中的自定义协议+序列反序列化用法

《Linux中的自定义协议+序列反序列化用法》文章探讨网络程序在应用层的实现,涉及TCP协议的数据传输机制、结构化数据的序列化与反序列化方法,以及通过JSON和自定义协议构建网络计算器的思路,强调分层... 目录一,再次理解协议二,序列化和反序列化三,实现网络计算器3.1 日志文件3.2Socket.hpp

C语言自定义类型之联合和枚举解读

《C语言自定义类型之联合和枚举解读》联合体共享内存,大小由最大成员决定,遵循对齐规则;枚举类型列举可能值,提升可读性和类型安全性,两者在C语言中用于优化内存和程序效率... 目录一、联合体1.1 联合体类型的声明1.2 联合体的特点1.2.1 特点11.2.2 特点21.2.3 特点31.3 联合体的大小1

springboot自定义注解RateLimiter限流注解技术文档详解

《springboot自定义注解RateLimiter限流注解技术文档详解》文章介绍了限流技术的概念、作用及实现方式,通过SpringAOP拦截方法、缓存存储计数器,结合注解、枚举、异常类等核心组件,... 目录什么是限流系统架构核心组件详解1. 限流注解 (@RateLimiter)2. 限流类型枚举 (

SpringBoot 异常处理/自定义格式校验的问题实例详解

《SpringBoot异常处理/自定义格式校验的问题实例详解》文章探讨SpringBoot中自定义注解校验问题,区分参数级与类级约束触发的异常类型,建议通过@RestControllerAdvice... 目录1. 问题简要描述2. 异常触发1) 参数级别约束2) 类级别约束3. 异常处理1) 字段级别约束

SpringBoot+EasyExcel实现自定义复杂样式导入导出

《SpringBoot+EasyExcel实现自定义复杂样式导入导出》这篇文章主要为大家详细介绍了SpringBoot如何结果EasyExcel实现自定义复杂样式导入导出功能,文中的示例代码讲解详细,... 目录安装处理自定义导出复杂场景1、列不固定,动态列2、动态下拉3、自定义锁定行/列,添加密码4、合并