uniapp 小程序实现底部tabbar的按钮
1 效果如图
2 实现步骤
2.1 先创建组件 因为是底部tabbar 这边就命名为uni-nav-foot文件夹
uni-nav-foot.vue
<template>
<view class="bottombox">
<view class="middlebox" @tap="toRectify">
<i class="iconfont icon-saoma"></i>
</view>
<view class="tableft" :class="type == 'userhome' ? 'activebtn' : ''" @tap="toHome">
<i class="iconfont icon-biaoqianlan_shouye"></i>
<view>首页</view>
</view>
<view class="tabright" :class="type == 'usermy' ? 'activebtn' : ''" @tap="toMy">
<i class="iconfont icon-wodedamaijihuo"></i>
<view>我的</view>
</view>
</view>
</template>
<script>
export default {
props: ['type'],
data() {
return {
userType: 0,
};
},
mounted() {
this.userType = uni.getStorageSync('userType');
},
methods: {
toRectify() {
uni.navigateTo({
url: '/pages/tabbar/profit/profit',
});
},
toHome() {
uni.reLaunch({
url: '/pages/tabbar/home/userhome',
});
},
toMy() {
uni.reLaunch({
url: '/pages/tabbar/my/usermy',
});
},
},
};
</script>
<style lang="scss" scoped>
.bottombox {
flex: none;
height: 100rpx;
background: #fff;
display: flex;
position: relative;
.tableft,
.tabright {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border-top: 1rpx solid rgba(0, 0, 0, 0.05);
box-sizing: border-box;
> i {
font-size: 48rpx;
color: #bfbdbe;
}
> view {
color: #939194;
font-size: 24rpx;
font-weight: 500;
line-height: 1em;
margin-top: 6rpx;
}
}
.activebtn {
> i {
color: #384ef3;
}
> view {
color: #384ef3;
}
}
.middlebox {
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, -36rpx);
width: 120rpx;
height: 120rpx;
border-radius: 50%;
background: #384ef3;
box-shadow: 0px 6px 12px 2px rgba(0, 0, 0, 0.16);
z-index: 10;
display: flex;
justify-content: center;
align-items: center;
> image {
width: 130rpx;
height: 130rpx;
}
> i {
font-size: 73rpx;
color: #fff;
}
}
}
</style>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
2.2 在需要的页面引入该组件 放在页面的最底部 当前页面的type等于在组件里边定义的值就可以了