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>
相关推荐
前端伪大叔3 分钟前
第13篇:🎯 如何精准控制买入卖出价格?entry/exit\_pricing 实战配置
javascript·python
荒诞英雄3 分钟前
菠萝滞销,帮帮我们(多个APP实例间pinia混乱)
前端·架构
zcyf08096 分钟前
rabbitmq分布式事务
java·spring boot·分布式·rabbitmq
llq_35010 分钟前
pnpm / Yarn / npm 覆盖依赖用法对比
前端
麦当_13 分钟前
ReAct 模式在 Neovate 中的应用
前端·javascript·架构
折七13 分钟前
告别传统开发痛点:AI 驱动的现代化企业级模板 Clhoria
前端·后端·node.js
程序00714 分钟前
纯html实现商品首页
前端
coderlin_14 分钟前
BI磁吸布局 (2) 基于react-grid-layout扩展的布局方式
前端·react.js·前端框架
Ankkaya16 分钟前
vue3 实现自定义模板表单打印
前端