uni-app 自定义tab组件

1.因老板越来越喜欢花里胡哨的Tab栏 有感写下自定义tab

<template>
	<view class="tabbar">
		<view class="uni-tabbar">
				<view class="uni-tabbar__item row-d row-c" v-for="(item,index) in tabbar" :key="index" @tap="changeTab(item)">
					<view :class="[item.pagePath==pagePath?'uni-active':'', 'row-d' ,'row-c']">
						<image :src="item.pagePath==pagePath?item.selectedIconPath:item.iconPath"></image>
						<view class="uni-tabbar__label">
							{{item.text}}
						</view>
					</view>
				</view>
			</view>
	</view>
</template>

<script>
	
	export  default {
		props: {
		            pagePath: null
		        },

		data() {
			return {
				page: 'contact',
				showPage: false,
				containerHeight: 400,
				tabbar: [
					{
						"pagePath": "/pages/home/home",
						"iconPath": "/static/home@2x.png",
						"selectedIconPath": "/static/home@2x (1).png",
						"text": "首页"
					},
					{
						"pagePath": "/pages/square/square",
						"iconPath": "/static/Book@2x.png",
						"selectedIconPath": "/static/Icon_explore@2x2.png",
						"text": "广场"
					},
					{
						"pagePath": "/pages/news/news",
						"iconPath": "/static/Books@2x.png",
						"selectedIconPath": "/static/Books@2x2.png",
						"text": "消息"
					},
					{
						"pagePath": "/pages/user/user",
						"iconPath": "/static/email-2@2x (1).png",
						"selectedIconPath": "/static/email-2@2x2.png",
						"text": "我的"
					}
				],
			}
		},
		created() {
			
		},
		methods: {
			changeTab(item) {
			                // this.page = item.pagePath;
			                uni.switchTab({
			                    url: item.pagePath,
			                });
			            }
		}
	}
</script>

<style lang="scss" scoped>
	.uni-tabbar {
	        position: fixed;
	        bottom: 0;
	        width: 100%;
	        display: flex;
	        justify-content: space-between;
	        background-color: #fff;
			height: 160rpx;
			border-radius: 56rpx 56rpx 0 0;
			box-shadow: 0rpx 4rpx 56rpx 0rpx rgba(0, 0, 0, 0.13);
			padding: 28rpx 50rpx 46rpx ;
			z-index: 16;
	        // box-shadow: 0px 0px 17upx 1upx rgba(206, 206, 206, 0.32);
	        .uni-tabbar__item {
	            // display: block;
				width: 96rpx;
				height: 112rpx;
				position: relative;
	            font-size: 12rpx;
	            text-align: center;
				color: #979797;
				.uni-active {
					
				}
				image{
					width: 48rpx;
					height: 48rpx;
					flex-shrink: 0;
				}
	        }
	        .uni-tabbar__label {
	            font-size: 12px;
				margin-top: 6rpx;
	        }
			.uni-active {
				width: 96rpx;
				height: 112rpx;
				color: #fff !important;
				border-radius: 16rpx;
				background:  linear-gradient(148.79deg, rgba(68, 0, 240, 1) 0%, rgba(221, 48, 255, 1) 100%);
				position: absolute;
				top: -52rpx;
			}
	    }
</style>

引用方法
1.在page.json 中的tabBar放上你的四个页面
2.在main.js 全局注册

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

2.在四个页面中写入 地址写你tab地址

<Tabbar :pagePath="'/pages/home/home'"></Tabbar>

效果图
在这里插入图片描述

愿各位前端好兄弟,早日提桶跑路

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值