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>
相关推荐
什巳20 分钟前
JAVA练习275-乘积最大子数组
java·开发语言·数据结构·算法
lang2015092825 分钟前
Apache POI Word(docx) 实战教程:从入门到精通表格合并、图片插入与文档合并
java·开发语言·word
小牛不牛的程序员26 分钟前
利用Claude Code构建自动化需求挖掘工具:从原理到实践
java·算法·自动化
wear工程师29 分钟前
腾讯天美一面:从 HashMap 到 Spring 事务,面试官这套连环问到底在考什么
java·面试
PBitW30 分钟前
为什么vite中TS报错,可以继续运行?Webpack不行?💡
前端·typescript
GISer_Jing40 分钟前
一套H5跑通三端:App+小程序内嵌H5跨端适配全栈解决方案
前端·前端框架·ai编程
码云之上1 小时前
项目团队从 5 人扩到 15 人,我写了个 CLI 让 IDE 共享 AI 规则
前端·人工智能·后端
飞天狗1 小时前
LCP / INP / CLS 三个维度的实战调优:把 Web Vitals 从不及格拉到优秀的完整路径
前端·性能优化