效果图如下
<template>
<view class="content">
<view class="main">
<page1 v-if="tabbarIndex == 0"></page1>
<page2 v-if="tabbarIndex == 1">
</page2>
<page3 v-if="tabbarIndex == 3"></page3>
<page4 v-if="tabbarIndex == 4"></page4>
</view>
<!-- tabbar底部导航栏 -->
<view class="tabbar-contaniner">
<view class="tabbar-item" v-for="(item, index) in list" :key="index">
<view v-if="index != 2" class="tab-item" @click="tabbarChange(item.path, index)">
<image class="tab-img" :src="current == index ? item.iconPath : item.icon"></image>
<text :class="{ tabTitle: true, select: current == index }">{
{ item.text }}</text>
</view>
<!-- 中间小圆球 -->
<view v-else class="tab-mid" >
<view class="txt1">+</view>
</view>
</view>
</view>
</view>
</template>
<script>
import page1 from '../page1/page1.vue'
import page2 from '../page2/page2.vue'
import page3 from '../page3/page3.vue'
import page4 from '../page4/page4.vue'
export default {
data() {
return {
title: 'Hello',
current:0,//底部tabbar
tabbarIndex:0,//页面的显示
list: [{
text: "首页",
icon: "/static/shouye.png", //未选中图标
iconPath: "/static/s-shouye.png", //选中图标
path: "/pages/page1" //页面路径
},
{
text: "运动",
icon: "/static/sport.png", //未选中图标
iconPath: "/static/s-sport.png", //选中图标
path: "/pages/page2" //页面路径
},
{
},//中间空闲位置
{
text: "消息",
icon: "/static/msg.png", //未选中图标
iconPath: "/static/s-msg.png", //选中图标
path:"/pages/page3" //页面路径
},
{
text: "我的",
icon: "/static/my.png", //未选中图标
iconPath: "/static/s-my.png", //选中图标
path: "/pages/page4" //页面路径
},
],
}
},
components:{
page1,
page2,
page3,
page4
},
onLoad() {
},
methods: {
tabbarChange(path, index) {
this.current = index;
this.tabbarIndex = index;
},
}
}
</script>
<style lang="scss" scoped>
.tabbar-contaniner {
height: 120rpx;
width: 100%;
display: flex;
align-items: center;
justify-content: space-evenly;
position: absolute;
position: fixed;
bottom: -4rpx;
left: 0;
z-index: 40;
background: url("/static/tabbarimg.png") no-repeat -49rpx center;
background-size: 847rpx;
background-color: transparent;
& .tabbar-item:nth-child(3) {
flex-shrink: 0;
width: 120rpx;
}
// & .tabbar-item:nth-child(2) {
// margin-left: 35rpx;
// }
}
.tab-item {
display: flex;
flex-direction: column;
font-size: 20rpx;
color: #828282;
align-items: center;
justify-content: center;
& .tab-img:first-child {
width: 46rpx;
height: 46rpx;
}
}
.tab-img {
width: 56rpx;
height: 56rpx;
margin-bottom: 10rpx;
}
.select {
color: #fd8dc4;
}
.tabbar-item {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
font-size: 14rpx;
width: 88rpx;
}
// 中间
.tab-mid {
background: #fd8dc4;
width: 110rpx;
height: 110rpx;
border-radius: 50%;
position: relative;
top: -39px;
z-index: 20;
font-size: 60rpx;
// color: #a060ff;
display: flex;
align-items: center;
justify-content: center;
}
.txt1{
color: #fff;
font-size: 70rpx;
line-height: 0;
padding-bottom: 10rpx;
}
</style>
所涉及到的页面。图片的话,自己去iconfont上面下载iconfont-阿里巴巴矢量图标库
底部导航栏的背景图:记得保存哦~