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

相关文章

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

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

macOS怎么轻松更换App图标? Mac电脑图标更换指南

《macOS怎么轻松更换App图标?Mac电脑图标更换指南》想要给你的Mac电脑按照自己的喜好来更换App图标?其实非常简单,只需要两步就能搞定,下面我来详细讲解一下... 虽然 MACOS 的个性化定制选项已经「缩水」,不如早期版本那么丰富,www.chinasem.cn但我们仍然可以按照自己的喜好来更换

SpringBoot 自定义消息转换器使用详解

《SpringBoot自定义消息转换器使用详解》本文详细介绍了SpringBoot消息转换器的知识,并通过案例操作演示了如何进行自定义消息转换器的定制开发和使用,感兴趣的朋友一起看看吧... 目录一、前言二、SpringBoot 内容协商介绍2.1 什么是内容协商2.2 内容协商机制深入理解2.2.1 内容

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

自定义类型:结构体(续)

目录 一. 结构体的内存对齐 1.1 为什么存在内存对齐? 1.2 修改默认对齐数 二. 结构体传参 三. 结构体实现位段 一. 结构体的内存对齐 在前面的文章里我们已经讲过一部分的内存对齐的知识,并举出了两个例子,我们再举出两个例子继续说明: struct S3{double a;int b;char c;};int mian(){printf("%zd\n",s

Spring 源码解读:自定义实现Bean定义的注册与解析

引言 在Spring框架中,Bean的注册与解析是整个依赖注入流程的核心步骤。通过Bean定义,Spring容器知道如何创建、配置和管理每个Bean实例。本篇文章将通过实现一个简化版的Bean定义注册与解析机制,帮助你理解Spring框架背后的设计逻辑。我们还将对比Spring中的BeanDefinition和BeanDefinitionRegistry,以全面掌握Bean注册和解析的核心原理。

Oracle type (自定义类型的使用)

oracle - type   type定义: oracle中自定义数据类型 oracle中有基本的数据类型,如number,varchar2,date,numeric,float....但有时候我们需要特殊的格式, 如将name定义为(firstname,lastname)的形式,我们想把这个作为一个表的一列看待,这时候就要我们自己定义一个数据类型 格式 :create or repla

uniapp设置微信小程序的交互反馈

链接:uni.showToast(OBJECT) | uni-app官网 (dcloud.net.cn) 设置操作成功的弹窗: title是我们弹窗提示的文字 showToast是我们在加载的时候进入就会弹出的提示。 2.设置失败的提示窗口和标签 icon:'error'是设置我们失败的logo 设置的文字上限是7个文字,如果需要设置的提示文字过长就需要设置icon并给

基于SpringBoot的宠物服务系统+uniapp小程序+LW参考示例

系列文章目录 1.基于SSM的洗衣房管理系统+原生微信小程序+LW参考示例 2.基于SpringBoot的宠物摄影网站管理系统+LW参考示例 3.基于SpringBoot+Vue的企业人事管理系统+LW参考示例 4.基于SSM的高校实验室管理系统+LW参考示例 5.基于SpringBoot的二手数码回收系统+原生微信小程序+LW参考示例 6.基于SSM的民宿预订管理系统+LW参考示例 7.基于

HTML5自定义属性对象Dataset

原文转自HTML5自定义属性对象Dataset简介 一、html5 自定义属性介绍 之前翻译的“你必须知道的28个HTML5特征、窍门和技术”一文中对于HTML5中自定义合法属性data-已经做过些介绍,就是在HTML5中我们可以使用data-前缀设置我们需要的自定义属性,来进行一些数据的存放,例如我们要在一个文字按钮上存放相对应的id: <a href="javascript:" d