uniapp 封装凸起导航栏

 

 

my-tabbar.vue

<template>
	<view>
		<view class="tabbar-container" :class="isIpx ? 'IpxBot' : ''">
			<view class="tabbar-item" v-for="(item, index) in tabList" :class="[item.centerItem ? 'center-item' : '']" @click="changeItem(item)" :key="index">
				<view class="item-top" :style="{ padding: item.id == 2 ? 0 : '8rpx' }"><image :src="tabId === item.id ? item.selectIcon : item.icon" mode=""></image></view>
				<view
					class="item-bottom"
					:style="[{ color: item.id == 2 ? '#fa3f22' : '' }, { fontWeight: item.id == 2 ? '700' : 'unset' }]"
					:class="[tabId === item.id ? 'item-active' : '']"
				>
					<text>{{ item.text }}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	props: {
		currentPage: {
			type: Number,
			default: 0
		}
	},
	data() {
		return {
			isIpx: false,
			tabId: 0,
			tabList: [
				{
					id: 0,
					path: '/pages/family/index',
					icon: '/static/tabBar/home.png',
					selectIcon: '/static/tabBar/homeon.png',
					text: '我的',
					centerItem: false
				},
				{
					id: 1,
					path: '/pages/task/index',
					icon: '/static/tabBar/TASKHAII.png',
					selectIcon: '/static/tabBar/TASKHAIIon.png',
					text: '展示',
					centerItem: false
				},
				{
					id: 2,
					path: '/pages/vip/index',
					icon: '/static/tabBar/vip.png',
					selectIcon: '/static/tabBar/vip.png',
					text: 'VIP',
					centerItem: true
				},
				{
					id: 3,
					path: '/pages/record/index',
					icon: '/static/tabBar/record.png',
					selectIcon: '/static/tabBar/recordon.png',
					text: '入驻',
					centerItem: false
				},
				{
					id: 4,
					path: '/pages/me/index',
					icon: '/static/tabBar/my.png',
					selectIcon: '/static/tabBar/myon.png',
					text: '我的',
					centerItem: false
				}
			]
		};
	},
	mounted() {
		this.tabId = this.currentPage;
		uni.hideTabBar();
	},
	created() {
		let that = this;
		uni.getSystemInfo({
			success: function(res) {
				if (res.model.indexOf('iPhone X') !== -1) {
					that.isIpx = true;
				}
			}
		});
	},
	methods: {
		changeItem(item) {
			this.tabId = item.id;
			uni.navigateTo({
				url: item.path
			});
		}
	}
};
</script>
<style scoped>
view {
	padding: 0;
	margin: 0;
	box-sizing: border-box;
}

.tabbar-container {
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	/* height: 100rpx; */
	/* box-shadow: 0 0 5px #999; */
	display: flex;
	align-items: center;
	padding: 5rpx 0;
	color: #999999;
	background-color: #ffffff;
}

.tabbar-container .tabbar-item {
	width: 20%;
	height: 100rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	text-align: center;
}

.tabbar-container .item-active {
	color: #f5cb2b;
}

.tabbar-container .center-item {
	display: block;
	position: relative;
}

.tabbar-container .tabbar-item .item-top {
	width: 70rpx;
	height: 70rpx;
	padding: 5rpx;
}

.tabbar-container .center-item .item-top {
	flex-shrink: 0;
	width: 78rpx;
	height: 84rpx;
	position: absolute;
	top: -28rpx;
	left: calc(50% - 40rpx);
	border-radius: 50%;
	/* box-shadow: 0 0 5px #999; */
	background-color: #ffffff;
}

.tabbar-container .tabbar-item .item-top image {
	width: 100%;
	height: 100%;
}

.tabbar-container .tabbar-item .item-bottom {
	font-size: 25rpx;
	width: 100%;
}

.tabbar-container .center-item .item-bottom {
	position: absolute;
	bottom: 2rpx;
}

/* 适配iPhone X */
.IpxBot {
	padding-bottom: 30rpx !important;
}
</style>

family.vue

<template>
	<view class="">
		<my-tabbar :currentPage="0"></my-tabbar>
	</view>
</template>

<script>
</script>

<style>
</style>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
***于Vue.js的跨平台开发框架,可以用于开发iOS、Android和Web应用。要封装顶部导航栏,可以通过以下步骤进行: 1. 在uniapp的项目目录中找到`/common`或者`/components`文件夹,没有的话可以自己创建一个。 2. 在该文件夹下创建一个新的Vue组件,比如命名为`TopNavBar.vue`。 3. 在`TopNavBar.vue`组件中,编写顶部导航栏的布局和样式。 4. 使用props接收需要的参数,比如导航栏的标题、是否显示返回按钮等。 5. 在`TopNavBar.vue`组件中,处理返回按钮点击事件,并通过emit向父组件传递事件。 6. 在需要使用顶部导航栏的页面中,引入`TopNavBar.vue`组件,并传入相应的参数。 以下是一个简单的示例代码: ```vue <template> <div class="top-nav-bar"> <div class="back-btn" @click="handleBack"> 返回 </div> <div class="title">{{ title }}</div> </div> </template> <script> export default { props: { title: String, showBackBtn: { type: Boolean, default: false } }, methods: { handleBack() { this.$emit('back'); } } } </script> <style scoped> .top-nav-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px; background-color: #333; color: #fff; } .back-btn { cursor: pointer; } .title { font-size: 18px; font-weight: bold; } </style> ``` 使用时,在需要的页面中引入组件,并传递相应的参数: ```vue <template> <view> <top-nav-bar title="顶部导航栏" show-back-btn @back="handleBack"></top-nav-bar> <!-- 页面内容 --> </view> </template> <script> import TopNavBar from '@/components/TopNavBar.vue' export default { components: { TopNavBar }, methods: { handleBack() { // 处理返回按钮点击事件 } } } </script> <style> /* 样式 */ </style> ``` 通过以上步骤,你就可以在uniapp封装顶部导航栏组件,并在需要使用的页面中引入和使用了。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值