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>
相关推荐
雨中飘荡的记忆1 小时前
大流量下库存扣减的数据库瓶颈:Redis分片缓存解决方案
java·redis·后端
炫饭第一名2 小时前
速通Canvas指北🦮——基础入门篇
前端·javascript·程序员
王晓枫2 小时前
flutter接入三方库运行报错:Error running pod install
前端·flutter
符方昊2 小时前
React 19 对比 React 16 新特性解析
前端·react.js
ssshooter2 小时前
又被 Safari 差异坑了:textContent 拿到的值居然没换行?
前端
曲折2 小时前
Cesium-气象要素PNG色斑图叠加
前端·cesium
Forever7_3 小时前
Electron 淘汰!新的桌面端框架 更强大、更轻量化
前端·vue.js
Angelial3 小时前
Vue3 嵌套路由 KeepAlive:动态缓存与反向配置方案
前端·vue.js
jiayu3 小时前
Angular学习笔记24:Angular 响应式表单 FormArray 与 FormGroup 相互嵌套
前端
jiayu3 小时前
Angular6学习笔记13:HTTP(3)
前端