uniapp 实现tabbar图标凸起

实现tabbar图标凸起有两种,第一种是自定义tabbar,第二种就是使用官方的tabbar跟api实现,自定义在体验中不如原生的tabbar,所以我下面展示的是使用官方的tabbar跟api实现

效果如图:

左边是未选中中间的凸起,右边是选中中间凸起,有一个问题就是我们选中凸起后文字颜色没有改变,目前我还没找到解决方案,有办法的兄弟们 可以留言

代码实现

tabbar

复制代码
"tabBar": {
		"borderStyle": "white",
		"backgroundColor": "white",
		"color": "#8F8F94",
		"selectedColor": "#e3b23e",
		"list": [{
				"pagePath": "pages/xxxx/xxxx",
				"iconPath": "static/uni.png",
				"selectedIconPath": "static/uni.png",
				"text": "主页"
			},
			{
				"pagePath": "pages/xxxx/xxxx",
				"iconPath": "static/uni.png",
				"selectedIconPath": "static/uni.png",
				"text": "积分榜"
			},
			{
				"pagePath": "pages/xxxx/xxxx",
				"iconPath": "static/c8.png",
				"selectedIconPath": "static/uni.png",
				"text": "订阅/下单",
				"visible": false
			},
			{
				"pagePath": "pages/xxxx/xxxx",
				"iconPath": "static/uni.png",
				"selectedIconPath": "static/uni.png",
				"text": "任务"
			},
			{
				"pagePath": "pages/xxxx/xxxx",
				"iconPath": "static/uni.png",
				"selectedIconPath": "static/uni.png",
				"text": "我的账户"
			}
		],
		"midButton": {
			"iconPath": "static/c8.png",
			"iconWidth": "60px",
			"height": "80px",
			"text": "订阅/下单"
		}
	}

midButton 中间按钮 仅在 list 项为偶数时有效,官方说明:

pages.json 页面路由 | uni-app官网

监听点击中的tabbar,并修改图标为选中状态 app.vue中监听

复制代码
// 点击中间按钮  
			uni.onTabBarMidButtonTap(() => {
				console.log('中间')
				uni.setTabBarStyle({
					midButton: {
						"iconPath": "static/uni.png",
						"iconWidth": "60px",
						"height": "80px",
						"text": "订阅/下单",
						"color": "red"
					}
				})
				uni.switchTab({
					url: '/pages/xxx/xxx'
				})
			})

然后在其他的tabbar list的页面监听tabbar点击,点击不是中间tabbar,为其他tabbar时 将中间tabbar又改为未选中状态

javascript 复制代码
<script>
	import {
		onTabItemTap
	} from "@dcloudio/uni-app"
	import {} from 'vue';

	export default {
		setup() {
			onTabItemTap((e) => {
				uni.setTabBarStyle({
					midButton: {
						"iconPath": "static/c8.png",
						"iconWidth": "60px",
						"height": "80px",
						"text": "订阅/下单"
					}
				})
			})

			return {
			};
		}
	};
</script>
相关推荐
特立独行的猫a几秒前
uni-app 开发HarmonyOS的鸿蒙影视项目分享:从实战案例到开源后台
uni-app·开源·harmonyos·鸿蒙·影视
胡斌附体3 分钟前
vue添加loading后修复页面渲染问题
前端·javascript·vue.js·渲染·v-if·异步加载
Dontla13 分钟前
Webpack DefinePlugin插件介绍(允许在编译时创建JS全局常量,常量可以在源代码中直接使用)JS环境变量
运维·javascript·webpack
酷爱码1 小时前
css中的 vertical-align与line-height作用详解
前端·css
沐土Arvin1 小时前
深入理解 requestIdleCallback:浏览器空闲时段的性能优化利器
开发语言·前端·javascript·设计模式·html
专注VB编程开发20年1 小时前
VB.NET关于接口实现与简化设计的分析,封装其他类
java·前端·数据库
小妖6661 小时前
css 中 content: “\e6d0“ 怎么变成图标的?
前端·css
L耀早睡2 小时前
mapreduce打包运行
大数据·前端·spark·mapreduce
咖啡の猫2 小时前
JavaScript基础-创建对象的三种方式
开发语言·javascript·ecmascript
HouGISer2 小时前
副业小程序YUERGS,从开发到变现
前端·小程序