uniApp自定义tabBar导航

uniapp写app之uniApp自定义tabBar导航

新建组件tabbar组件

在这里插入图片描述

自定义一个tabbar导航,动态tabbar导航,在需要tabbar的页面引入tabbar组件,跳转到不同系统有不同tabbar导航我这里是后端设置字段控制的,ios和android进入不同系统。

// An highlighted block
<template>
	<view class="tab-bar-box">
		<view class="tab-bar">
			<view class="content">
				<view class="one-tab" v-for="(item, index) in tabBarList" :key="index" @click="selectTabBar(item.pagePath)">
					<view>
						<view class="tab-img">
							<image v-if="routePath === item.pagePath" class="img" :src="item.selectedIconPath"></image>
							<image v-else class="img" :src="item.iconPath"></image>
						</view>
					</view>
					<view class="tit">{{ item.text }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';
import {appNavBer,shopNavber} from '@/config/tabBar.js';
export default {
	props: {
		// 当前页面路径
		routePath: {
			type: String,
			required: true
		},
	},
	data() {
		return {
			tabBarList: [],
			appNavBer: appNavBer,
			shopNavber: shopNavber,
		};
	},
	created() {
		if (this.$appName == 'app') {
			this.tabBarList = this.appNavBer
		} else {
			this.tabBarList = this.shopNavber
		}
	},
	
	methods: {
		selectTabBar(path) {
			if (path==this.routePath) return
			if (this.$appName == 'app') {
				uni.switchTab({
					url:path
				})
			} else {
				uni.reLaunch({
					url: path
				})
			}
		}
	}
};
</script>

<style lang="less">
	.tab-bar-box {
		height: 100rpx;
	}
.tab-bar {
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100vw;
	padding: 20rpx;
	padding-bottom: 0;
	padding-bottom: 0;
	background-color: #fff;

	.content {
		display: flex;

		.one-tab {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 50%;

			.tab-img {
				width: 50rpx;
				height: 50rpx;

				.img {
					width: 100%;
					height: 100%;
				}
			}

			.tit {
				font-size: 24rpx;
				transform: scale(0.7);
			}
		}
	}
}
</style>



在父组件中使用

引入父组件中

<template>
	<view>
		<tabbar routePath="/pages/index/index"></tabbar>
	</view>
</template>
<script>
	import tabbar from '@/components/tabbar.vue'
	export default {
		components: {
			tabbar,
		},
		onLoad() {
			//隐藏原有tabbar
			uni.hideTabBar()
			
		},
	}
</script>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值