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>
相关推荐
前端大白话几秒前
震惊!90%前端工程师都踩过的坑!computed属性vs methods到底该怎么选?一文揭秘高效开发密码
前端·vue.js·设计模式
一天睡25小时几秒前
React与Vue表单的对比差异
前端·javascript
作曲家种太阳几秒前
第七章 响应式的 watch 实现【手摸手带你实现一个vue3】
前端
在澳门喝茶的芦竹2 分钟前
React高阶组件——React.momo
javascript·react.js
前端小巷子3 分钟前
深入解析 iframe
前端
WEI_Gaot3 分钟前
ES6 模板字符串
前端·javascript
前端大白话3 分钟前
前端工程师必看!手把手教你用CSS实现超丝滑的自适应视频嵌入
前端·css·前端框架
前端大白话3 分钟前
前端必看!figure标签在响应式图片排版中的王炸操作,grid/flex布局实战指南
前端·设计模式·html
长欢3 分钟前
保持元素宽高比
javascript
前端大白话5 分钟前
深入理解 JavaScript 中 async 函数与 await 关键字的执行奥秘
前端·javascript·架构