当前位置:   article > 正文

uniapp 封装凸起导航栏_uniapp做底部导航凸起

uniapp做底部导航凸起

 

 

my-tabbar.vue

  1. <template>
  2. <view>
  3. <view class="tabbar-container" :class="isIpx ? 'IpxBot' : ''">
  4. <view class="tabbar-item" v-for="(item, index) in tabList" :class="[item.centerItem ? 'center-item' : '']" @click="changeItem(item)" :key="index">
  5. <view class="item-top" :style="{ padding: item.id == 2 ? 0 : '8rpx' }"><image :src="tabId === item.id ? item.selectIcon : item.icon" mode=""></image></view>
  6. <view
  7. class="item-bottom"
  8. :style="[{ color: item.id == 2 ? '#fa3f22' : '' }, { fontWeight: item.id == 2 ? '700' : 'unset' }]"
  9. :class="[tabId === item.id ? 'item-active' : '']"
  10. >
  11. <text>{{ item.text }}</text>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. props: {
  20. currentPage: {
  21. type: Number,
  22. default: 0
  23. }
  24. },
  25. data() {
  26. return {
  27. isIpx: false,
  28. tabId: 0,
  29. tabList: [
  30. {
  31. id: 0,
  32. path: '/pages/family/index',
  33. icon: '/static/tabBar/home.png',
  34. selectIcon: '/static/tabBar/homeon.png',
  35. text: '我的',
  36. centerItem: false
  37. },
  38. {
  39. id: 1,
  40. path: '/pages/task/index',
  41. icon: '/static/tabBar/TASKHAII.png',
  42. selectIcon: '/static/tabBar/TASKHAIIon.png',
  43. text: '展示',
  44. centerItem: false
  45. },
  46. {
  47. id: 2,
  48. path: '/pages/vip/index',
  49. icon: '/static/tabBar/vip.png',
  50. selectIcon: '/static/tabBar/vip.png',
  51. text: 'VIP',
  52. centerItem: true
  53. },
  54. {
  55. id: 3,
  56. path: '/pages/record/index',
  57. icon: '/static/tabBar/record.png',
  58. selectIcon: '/static/tabBar/recordon.png',
  59. text: '入驻',
  60. centerItem: false
  61. },
  62. {
  63. id: 4,
  64. path: '/pages/me/index',
  65. icon: '/static/tabBar/my.png',
  66. selectIcon: '/static/tabBar/myon.png',
  67. text: '我的',
  68. centerItem: false
  69. }
  70. ]
  71. };
  72. },
  73. mounted() {
  74. this.tabId = this.currentPage;
  75. uni.hideTabBar();
  76. },
  77. created() {
  78. let that = this;
  79. uni.getSystemInfo({
  80. success: function(res) {
  81. if (res.model.indexOf('iPhone X') !== -1) {
  82. that.isIpx = true;
  83. }
  84. }
  85. });
  86. },
  87. methods: {
  88. changeItem(item) {
  89. this.tabId = item.id;
  90. uni.navigateTo({
  91. url: item.path
  92. });
  93. }
  94. }
  95. };
  96. </script>
  97. <style scoped>
  98. view {
  99. padding: 0;
  100. margin: 0;
  101. box-sizing: border-box;
  102. }
  103. .tabbar-container {
  104. position: fixed;
  105. bottom: 0;
  106. left: 0;
  107. width: 100%;
  108. /* height: 100rpx; */
  109. /* box-shadow: 0 0 5px #999; */
  110. display: flex;
  111. align-items: center;
  112. padding: 5rpx 0;
  113. color: #999999;
  114. background-color: #ffffff;
  115. }
  116. .tabbar-container .tabbar-item {
  117. width: 20%;
  118. height: 100rpx;
  119. display: flex;
  120. flex-direction: column;
  121. justify-content: center;
  122. align-items: center;
  123. text-align: center;
  124. }
  125. .tabbar-container .item-active {
  126. color: #f5cb2b;
  127. }
  128. .tabbar-container .center-item {
  129. display: block;
  130. position: relative;
  131. }
  132. .tabbar-container .tabbar-item .item-top {
  133. width: 70rpx;
  134. height: 70rpx;
  135. padding: 5rpx;
  136. }
  137. .tabbar-container .center-item .item-top {
  138. flex-shrink: 0;
  139. width: 78rpx;
  140. height: 84rpx;
  141. position: absolute;
  142. top: -28rpx;
  143. left: calc(50% - 40rpx);
  144. border-radius: 50%;
  145. /* box-shadow: 0 0 5px #999; */
  146. background-color: #ffffff;
  147. }
  148. .tabbar-container .tabbar-item .item-top image {
  149. width: 100%;
  150. height: 100%;
  151. }
  152. .tabbar-container .tabbar-item .item-bottom {
  153. font-size: 25rpx;
  154. width: 100%;
  155. }
  156. .tabbar-container .center-item .item-bottom {
  157. position: absolute;
  158. bottom: 2rpx;
  159. }
  160. /* 适配iPhone X */
  161. .IpxBot {
  162. padding-bottom: 30rpx !important;
  163. }
  164. </style>

family.vue

  1. <template>
  2. <view class="">
  3. <my-tabbar :currentPage="0"></my-tabbar>
  4. </view>
  5. </template>
  6. <script>
  7. </script>
  8. <style>
  9. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/113162
推荐阅读
相关标签