tabbar.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="tabbar-container">
  3. <block>
  4. <view class="tabbar-item" v-for="(item, index) in tabbarList" :key="index" :class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)">
  5. <view class="item-top"><image :src="currentItem == item.id ? item.selectIcon : item.icon"></image></view>
  6. <view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']">
  7. <text>{{ item.text }}</text>
  8. </view>
  9. </view>
  10. </block>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. props: {
  16. currentPage: {
  17. type: Number,
  18. default: 0
  19. }
  20. },
  21. data() {
  22. return {
  23. currentItem: 0,
  24. tabbarList: [
  25. {
  26. id: 0,
  27. path: '/packageShang/pages/tabbar/home',
  28. icon: '/packageShang/static/images/tabbar/home.png',
  29. selectIcon: '/packageShang/static/images/tabbar/home-active.png',
  30. text: '首页',
  31. centerItem: false
  32. },
  33. {
  34. id: 1,
  35. path: '/packageShang/pages/tabbar/category',
  36. icon: '/packageShang/static/images/tabbar/category.png',
  37. selectIcon: '/packageShang/static/images/tabbar/category-active.png',
  38. text: '分类',
  39. centerItem: true
  40. },
  41. {
  42. id: 2,
  43. path: '/packageShang/pages/tabbar/cart',
  44. icon: '/packageShang/static/images/tabbar/cart.png',
  45. selectIcon: '/packageShang/static/images/tabbar/cart-active.png',
  46. text: '购物车',
  47. centerItem: false
  48. },
  49. {
  50. id: 3,
  51. path: '/packageShang/pages/tabbar/user',
  52. icon: '/packageShang/static/images/tabbar/user.png',
  53. selectIcon: '/packageShang/static/images/tabbar/user-active.png',
  54. text: '我的',
  55. centerItem: false
  56. }
  57. ]
  58. };
  59. },
  60. mounted() {
  61. this.currentItem = this.currentPage;
  62. uni.hideTabBar();
  63. },
  64. methods: {
  65. changeItem(item) {
  66. let _this = this;
  67. //_this.currentItem = item.id;
  68. uni.redirectTo({
  69. url: item.path
  70. });
  71. }
  72. }
  73. };
  74. </script>
  75. <style>
  76. view {
  77. padding: 0;
  78. margin: 0;
  79. box-sizing: border-box;
  80. }
  81. .tabbar-container {
  82. position: fixed;
  83. bottom: 0;
  84. left: 0;
  85. width: 100%;
  86. height: 167rpx;
  87. box-shadow: 0 0 5px #999;
  88. display: flex;
  89. align-items: center;
  90. padding: 5rpx 0;
  91. color: #999999;
  92. background-color: white;
  93. /* background-image: url('../static/images/tabbar/bgkuang.png'); */
  94. background-size: 100%;
  95. }
  96. .tabbar-container .tabbar-item {
  97. width: 33%;
  98. height: 100rpx;
  99. display: flex;
  100. flex-direction: column;
  101. justify-content: center;
  102. align-items: center;
  103. text-align: center;
  104. }
  105. .tabbar-container .item-active {
  106. color: #1E7DFB;
  107. }
  108. .tabbar-container .center-item {
  109. display: block;
  110. position: relative;
  111. }
  112. .tabbar-container .tabbar-item .item-top {
  113. width: 70rpx;
  114. height: 70rpx;
  115. padding: 10rpx;
  116. top: 24px;
  117. position: absolute;
  118. }
  119. .tabbar-container .center-item .item-top {
  120. flex-shrink: 0;
  121. width: 70rpx;
  122. height: 70rpx;
  123. position: absolute;
  124. top: 10rpx;
  125. left: calc(60% - 50rpx);
  126. border-radius: 50%;
  127. /* box-shadow: 0 0 5px #999; */
  128. /* background-color: #ffffff; */
  129. }
  130. .tabbar-container .tabbar-item .item-top image {
  131. width: 100%;
  132. height: 100%;
  133. }
  134. .tabbar-container .tabbar-item .item-bottom {
  135. font-size: 28rpx;
  136. width: 100%;
  137. top: 55px;
  138. position: absolute;
  139. }
  140. .tabbar-container .center-item .item-bottom {
  141. position: absolute;
  142. top: 37px;
  143. position: absolute;
  144. }
  145. </style>