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

相关文章

使用Sentinel自定义返回和实现区分来源方式

《使用Sentinel自定义返回和实现区分来源方式》:本文主要介绍使用Sentinel自定义返回和实现区分来源方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Sentinel自定义返回和实现区分来源1. 自定义错误返回2. 实现区分来源总结Sentinel自定

macOS无效Launchpad图标轻松删除的4 种实用方法

《macOS无效Launchpad图标轻松删除的4种实用方法》mac中不在appstore上下载的应用经常在删除后它的图标还残留在launchpad中,并且长按图标也不会出现删除符号,下面解决这个问... 在 MACOS 上,Launchpad(也就是「启动台」)是一个便捷的 App 启动工具。但有时候,应

如何自定义Nginx JSON日志格式配置

《如何自定义NginxJSON日志格式配置》Nginx作为最流行的Web服务器之一,其灵活的日志配置能力允许我们根据需求定制日志格式,本文将详细介绍如何配置Nginx以JSON格式记录访问日志,这种... 目录前言为什么选择jsON格式日志?配置步骤详解1. 安装Nginx服务2. 自定义JSON日志格式各

Android自定义Scrollbar的两种实现方式

《Android自定义Scrollbar的两种实现方式》本文介绍两种实现自定义滚动条的方法,分别通过ItemDecoration方案和独立View方案实现滚动条定制化,文章通过代码示例讲解的非常详细,... 目录方案一:ItemDecoration实现(推荐用于RecyclerView)实现原理完整代码实现

基于Spring实现自定义错误信息返回详解

《基于Spring实现自定义错误信息返回详解》这篇文章主要为大家详细介绍了如何基于Spring实现自定义错误信息返回效果,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录背景目标实现产出背景Spring 提供了 @RestConChina编程trollerAdvice 用来实现 HTT

SpringSecurity 认证、注销、权限控制功能(注销、记住密码、自定义登入页)

《SpringSecurity认证、注销、权限控制功能(注销、记住密码、自定义登入页)》SpringSecurity是一个强大的Java框架,用于保护应用程序的安全性,它提供了一套全面的安全解决方案... 目录简介认识Spring Security“认证”(Authentication)“授权” (Auth

SpringBoot自定义注解如何解决公共字段填充问题

《SpringBoot自定义注解如何解决公共字段填充问题》本文介绍了在系统开发中,如何使用AOP切面编程实现公共字段自动填充的功能,从而简化代码,通过自定义注解和切面类,可以统一处理创建时间和修改时间... 目录1.1 问题分析1.2 实现思路1.3 代码开发1.3.1 步骤一1.3.2 步骤二1.3.3

Python使用PIL库将PNG图片转换为ICO图标的示例代码

《Python使用PIL库将PNG图片转换为ICO图标的示例代码》在软件开发和网站设计中,ICO图标是一种常用的图像格式,特别适用于应用程序图标、网页收藏夹图标等场景,本文将介绍如何使用Python的... 目录引言准备工作代码解析实践操作结果展示结语引言在软件开发和网站设计中,ICO图标是一种常用的图像

dubbo3 filter(过滤器)如何自定义过滤器

《dubbo3filter(过滤器)如何自定义过滤器》dubbo3filter(过滤器)类似于javaweb中的filter和springmvc中的intercaptor,用于在请求发送前或到达前进... 目录dubbo3 filter(过滤器)简介dubbo 过滤器运行时机自定义 filter第一种 @A

CSS自定义浏览器滚动条样式完整代码

《CSS自定义浏览器滚动条样式完整代码》:本文主要介绍了如何使用CSS自定义浏览器滚动条的样式,包括隐藏滚动条的角落、设置滚动条的基本样式、轨道样式和滑块样式,并提供了完整的CSS代码示例,通过这些技巧,你可以为你的网站添加个性化的滚动条样式,从而提升用户体验,详细内容请阅读本文,希望能对你有所帮助...