微信小程序原生的tabbar一个项目只能有一个,我想要在多个页面都能使用不同的tabbar,就找到伪tabbar这种方法,通过点击元素实现页面跳转。
新建文件夹:
tabbarStudy.wxml
<view>
<view>个人中心</view>
<!-- 伪tabBar -->
<view class='tabBar'>
<view class='tabBar-left' catchtap='home'>
<view class='tabBar-left-content-top'>
<image class='tabBar-left-content-img' src='../../../images/home_out.png'/>
</view>
<view class='tabBar-left-content-bottom'>
<label class='tabBar-left-content-label'>首页</label>
</view>
</view>
<view class='tabBar-right' catchtap='mine'>
<view class='tabBar-right-content-top'>
<image class='tabBar-right-content-img' src='../../../images/my_in.png'/>
</view>
<view class='tabBar-right-content-bottom'>
<label class='tabBar-right-content-label'>我的</label>
</view>
</view>
</view>
</view>
tabbarStudy.wxss
/* 伪tabBar */
.tabBar {
background-color: white;
border-top: 1rpx solid #a9b7b7;
color: "#a9b7b7";
width: 100%;
height: 100rpx;
position: fixed;
bottom: 0rpx;
display: flex;
flex-direction: row;
/* justify-content: space-around; */
}
.tabBar-left {
background-color: white;
color: "#a9b7b7";
width: 50%;
height: 100rpx;
display: flex;
flex-direction: column;
}
.tabBar-left-content-top {
background-color: white;
color: "#a9b7b7";
width: 100%;
height: 70rpx;
display: flex;
flex-direction: row;
justify-content: space-around;
margin-top: 10rpx;
}
.tabBar-left-content-img {
width: 50rpx;
height: 50rpx;
}
.tabBar-left-content-bottom {
background-color: white;
color: "#a9b7b7";
width: 100%;
height: 30rpx;
display: flex;
flex-direction: row;
justify-content: space-around;
}
.tabBar-left-content-label {
text-align: center;
font-size: 25rpx;
line-height: 25rpx;
height: 25rpx;
color: #a9b7b7;
}
.tabBar-right {
background-color: white;
color: "#a9b7b7";
width: 50%;
height: 100rpx;
display: flex;
flex-direction: column;
}
.tabBar-right-content-top {
background-color: white;
color: "#a9b7b7";
width: 100%;
height: 70rpx;
display: flex;
flex-direction: row;
justify-content: space-around;
margin-top: 10rpx;
}
.tabBar-right-content-img {
width: 50rpx;
height: 50rpx;
}
.tabBar-right-content-bottom {
background-color: white;
color: "#a9b7b7";
width: 100%;
height: 30rpx;
display: flex;
flex-direction: row;
justify-content: space-around;
}
.tabBar-right-content-label {
text-align: center;
font-size: 25rpx;
line-height: 25rpx;
height: 25rpx;
color: #a9b7b7;
}
tabbarStudy.js
myCenter文件与上面的类似,不同之处
运行结果:
伪tabbar的不足:跳转的时候会出现闪烁