h5的底部导航栏模板

复制代码
<template>
	<view class="tabbarBox">
		<view class="tabbar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
			<view class="tabbar-item" v-for="(item, index) in list" :key="index" @click="tabbarChange(item.path)">
				<image class="item-img" :src="item.icon_a" v-if="current == index"></image>
				<image class="item-img" :src="item.icon" v-else></image>
				<view class="item-name" :class="{'tabbarActive': current == index}" 
				v-if="item.text">
					{{item.text}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			current: 0
		},
		data() {
			return {
				paddingBottomHeight: 0, //苹果X以上手机底部适配高度
				list: [{
					text: '首页',
					icon: '../../../static/image/shop/user-order/Frame 31@2x.png', //未选中图标
					icon_a: '../../../static/image/shop/user-order/Frame 31@2x.png', //选中图片
					path: "", //页面路径
				}, {
					text: '分类',
					icon: '../../../static/image/shop/user-order/Frame.png', //未选中图标
					icon_a: '../../../static/image/shop/user-order/Frame.png', //选中图片
					path: "",
				}, {
					text: '购物车',
					icon: '../../../static/image/shop/user-order/Frame@2x(1).png', //未选中图标
					icon_a: '../../../static/image/shop/user-order/Frame@2x(1).png', //选中图片
					path: '',
				}, {
					text: '订单',
					icon: '../../../static/image/shop/user-order/Frame@2x(2).png', //未选中图标
					icon_a: '../../../static/image/shop/user-order/Frame@2x(2).png', //选中图片
					path: "",
				}, ]
			};
		},
		created() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
					model.forEach(item => {
						//适配iphoneX以上的底部,给tabbar一定高度的padding-bottom
						if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
							that.paddingBottomHeight = 40;
						}
					})
				}
			});
		},
		methods: {
			tabbarChange(path) {
				uni.navigateTo({
					url:path
				})
			}
		}
	};
</script>

<style lang="less" scoped>
	.tabbarActive {
		color: #0EB87E !important;
	}

	.tabbarBox {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		// background-image: url(../../static/image/index/tabsBG.png);
		// background-color: #096;
		// background-size: 100% 160rpx;
		// background-repeat: no-repeat;
		// height: 160rpx;
		// width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		border: 2rpx solid #F0F0F0;


		.tabbar {
			box-sizing: border-box;			
			// background-color: #ffffff;
			position: fixed;
			bottom: 10rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			width: 100%;
			height: 100rpx;
			margin-left: -10rpx;

			.tabbar-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				height: 100rpx;

				.item-img {
					width: 44rpx;
					height: 44rpx;
					margin-bottom: 4rpx;
				}

				.item-name {
					// width: 48rpx;
					height: 24rpx;
					margin-left: 0rpx;
					margin-top: 12rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #8B8B8B;
					line-height: 24rpx;
					text-align: center;
					font-style: normal;
					text-transform: none;
				}
			}
		}
	}
</style>

上面是组件

效果图:

引入部分

复制代码
<template>
	<view class="content">
		<view-tabbar :current="1"></view-tabbar>      //:current="1"  当前页面是第几个
	</view>
</template>

<script>
	import Tabbar from '@/components/tabbar/tabbar.vue'
	export default {
		components: {
			'view-tabbar': Tabbar
		},
		data() {
			return {

			}
		},
		onLoad() {

		},
		methods: {

		}

	}
</script>

<style>

</style>
相关推荐
祈祷苍天赐我java之术1 小时前
Linux 进阶之性能调优,文件管理,网络安全
java·linux·运维
无处不在的海贼2 小时前
小明的Java面试奇遇之发票系统相关深度实战挑战
java·经验分享·面试
武子康2 小时前
Java-109 深入浅出 MySQL MHA主从故障切换机制详解 高可用终极方案
java·数据库·后端·mysql·性能优化·架构·系统架构
秋难降2 小时前
代码界的 “建筑师”:建造者模式,让复杂对象构建井然有序
java·后端·设计模式
秋名山大前端3 小时前
Chrome GPU 加速优化配置(前端 3D 可视化 / 数字孪生专用)
前端·chrome·3d
今天不要写bug3 小时前
antv x6实现封装拖拽流程图配置(适用于工单流程、审批流程应用场景)
前端·typescript·vue·流程图
luquinn3 小时前
实现统一门户登录跳转免登录
开发语言·前端·javascript
BillKu3 小时前
Spring Boot 多环境配置
java·spring boot·后端
用户21411832636023 小时前
dify案例分享-5分钟搭建智能思维导图系统!Dify + MCP工具实战教程
前端
augenstern4163 小时前
HTML(面试)
前端