使用colorui自定义个好看的tabbar

  1. 定义tabbar组件
  2. 页面中引用该组件
  3. 隐藏原有的tabbar

tabbar组件

<template>
	<view>
		<view class="cu-bar tabbar bg-white pos-bottom">
			<view class="action" @click="setTab(item)" v-for="(item,index) in tabbar" :key="index" :class="{'text-green':tabIndex == index,'text-gray add-action':item.center}">
				<view v-if="item.center">
					<button class="cu-btn cuIcon-add bg-orange shadow"></button>
				</view> 
				<view :class="item.icon" v-else></view> {{item.text}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index: 0,
				tabbar: [{
						icon: "cuIcon-homefill",
						text: "首页",
						page: "../index/index",
						center: false
					},
					{
						icon: "cuIcon-myfill",
						text: "我的",
						page: "../home/home",
						center: false
					},
				],
			}
		},
		name: 'tabbar',
		computed: {

		},
		props: {
			tabIndex: {
				type: Number,
				default: 0
			}
		},
		mounted() {
			this.index = this.tabIndex;
		},
		methods: {
			setTab(item) {
				uni.switchTab({
					url:item.page
				})
			}
		}
	}
</script>

<style>
</style>
另外还需要在App.vue中改它一点样式
.pos-bottom {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
	}

在首页和我的主页中用它

引用之前需要在main.js中把它挂载到vue上
// 载入tabbar
import tabbar from 'pages/comporents/tabbar.vue'
Vue.component('tabbar', tabbar)

首页中:
<tabbar tabIndex="0"></tabbar>
我的中:
<tabbar tabIndex="1"></tabbar>

隐藏原有的tabbar

这里有两种方式
1  App.vue中
onLaunch: function() {
	console.log('App Launch')
		// 隐藏tabbar
		// uni.hideTabBar()
	}

2  pages.json中
"tabBar": {
		// 自定义tabbar 隐藏它
		"custom": true,
		...
	}

tip:
推荐使用第二种隐藏原有的tabbar,onLaunch中隐藏还是有时候会闪现一下原有的tabbar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值