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>
相关推荐
moxiaoran575314 分钟前
uni-app学习笔记三十--request网络请求传参
笔记·学习·uni-app
Angel_girl31929 分钟前
vue项目使用svg图标
前端·vue.js
難釋懷34 分钟前
vue 项目中常用的 2 个 Ajax 库
前端·vue.js·ajax
Qian Xiaoo36 分钟前
Ajax入门
前端·ajax·okhttp
爱生活的苏苏1 小时前
vue生成二维码图片+文字说明
前端·vue.js
拉不动的猪1 小时前
安卓和ios小程序开发中的兼容性问题举例
前端·javascript·面试
炫彩@之星1 小时前
Chrome书签的导出与导入:步骤图
前端·chrome
贩卖纯净水.1 小时前
浏览器兼容-polyfill-本地服务-优化
开发语言·前端·javascript
前端百草阁1 小时前
从npm库 Vue 组件到独立SDK:打包与 CDN 引入的最佳实践
前端·vue.js·npm
夏日米米茶1 小时前
Windows系统下npm报错node-gyp configure got “gyp ERR“解决方法
前端·windows·npm