uniapp自定义tabbar——中间特殊按钮

方法一:原生tabbar,修改中间图标的样式

![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/7959e1be5f994f4c9fd88822fe656056.png

  • pages.json
"tabBar": {
		"color": "#cccccc",
		"selectedColor": "#2979ff",
		"borderStyle": "black",
		"backgroundColor": "#ffffff",
		"list": [
			{
				"pagePath": "pages/message/index",
				"iconPath": "static/tabbar/5.png",
				"selectedIconPath": "static/tabbar/5-5.png",
				"text": "消息"
			},
			{
				"pagePath": "pages/home/index",
				"iconPath": "static/tabbar/logo.jpeg",
				"selectedIconPath": "static/tabbar/logo.jpeg",
				"text": ""
			},
			{
				"pagePath": "pages/my/index",
				"iconPath": "static/tabbar/6.png",
				"selectedIconPath": "static/tabbar/6-6.png",
				"text": "我的"
			}
		]
	}
  • 样式覆盖 App.vue
// 底部tabbar
.uni-tabbar__item:nth-child(3) .uni-tabbar__icon {
	width: 36px !important;
	height: 36px !important;
}
 
  • 消息设置角标
uni.setTabBarBadge({
	index: 0,
	text: '2'
})

方法二:uview2.0自定义tabbar组件,适用任意情况

在这里插入图片描述

tabbar组件

<template>
	<u-tabbar :value="tab" @change="changeTab" :fixed="true" :border="true" :placeholder="true"
		:safeAreaInsetBottom="true">
		<u-tabbar-item text="消息" icon="chat" badge="3"></u-tabbar-item>
		<u-tabbar-item text="">
			<image style="width: 80rpx;height: 80rpx;" slot="active-icon" src="../static/wallet.png"></image>
			<image style="width: 80rpx;height: 80rpx;" slot="inactive-icon" src="../static/wallet.png"></image>
		</u-tabbar-item>
		<u-tabbar-item text="设置" icon="setting"></u-tabbar-item>
	</u-tabbar>
</template>

<script>
	export default {
		props: {
			tab: {
				type: Number,
				require: true
			},
		},
		data() {
			return {
				list: ["/pages/message/index", '/pages/home/index', "/pages/set/index"]
			}
		},
		methods: {
			changeTab(name) {
				console.log(88, name)
				uni.reLaunch({
					url: this.list[name]
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}
</style>

main.js全局组件注册

import tabbar from './components/tabbar.vue'
Vue.component('tabbar', tabbar)

主页面使用

  • 在三个主页面分别引入组件
  • 传入对于的索引即可
<!-- 自定义底部-->
<tabbar :tab="1"></tabbar>

方法三:uniapp配置midButton:适用点击中间图标跳转非tabbar页面

在这里插入图片描述

pages.json配置midButton

"tabBar": {
		"color": "#cccccc",
		"selectedColor": "#E84118",
		"borderStyle": "black",
		"backgroundColor": "#ffffff",
		"list": [{
			"pagePath": "pages/home/index",
			"iconPath": "static/tabbar/1.png",
			"selectedIconPath": "static/tabbar/1-1.png",
			"text": "首页"
		}, {
			"pagePath": "pages/classify/index",
			"iconPath": "static/tabbar/2.png",
			"selectedIconPath": "static/tabbar/2-2.png",
			"text": "分类"
		}, {
			"pagePath": "pages/cart/index",
			"iconPath": "static/tabbar/3.png",
			"selectedIconPath": "static/tabbar/3-3.png",
			"text": "购物车"
		}, {
			"pagePath": "pages/my/index",
			"iconPath": "static/tabbar/4.png",
			"selectedIconPath": "static/tabbar/4-4.png",
			"text": "我的"
		}],
		// 中间按钮
		"midButton": {
			"pagePath": "pages/my/index",
			"width": "60px",
			"height": "45px",
			"text": "",
			"iconPath": "static/wallet.png",
			"iconWidth": "40px"
		}
	}

app.vue

		onLaunch: function() {
			console.log('App Launch')
			uni.onTabBarMidButtonTap(() => {
				uni.navigateTo({
					url: '/pages/home/list',
				});
			})
		},
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小曲曲

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值