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>
相关推荐
UI前端开发工作室11 分钟前
数字孪生技术为UI前端提供新视角:产品性能的实时模拟与预测
大数据·前端
Sapphire~14 分钟前
重学前端004 --- html 表单
前端·html
今天背单词了吗98016 分钟前
算法学习笔记:17.蒙特卡洛算法 ——从原理到实战,涵盖 LeetCode 与考研 408 例题
java·笔记·考研·算法·蒙特卡洛算法
Dcs19 分钟前
从 C 到 Rust:一位开发者的 `tmux` 全面移植之旅
java
Maybyy37 分钟前
力扣242.有效的字母异位词
java·javascript·leetcode
遇到困难睡大觉哈哈41 分钟前
CSS中的Element语法
前端·css
Real_man1 小时前
新物种与新法则:AI重塑开发与产品未来
前端·后端·面试
小彭努力中1 小时前
147.在 Vue3 中使用 OpenLayers 地图上 ECharts 模拟飞机循环飞行
前端·javascript·vue.js·ecmascript·echarts
老马聊技术1 小时前
日历插件-FullCalendar的详细使用
前端·javascript
zhu_zhu_xia1 小时前
cesium添加原生MVT矢量瓦片方案
javascript·arcgis·webgl·cesium