index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="tabBar">
  3. <view v-for="(item,index) in tabBar" :key="item.url" class="tabbar_item" :class="{'active':item.url == currentPage}" @click="navTo(item)">
  4. <image v-if="item.url == currentPage" :src="item.imgClick" mode=""></image>
  5. <image v-else :src="item.imgNormal" mode=""></image>
  6. <view class="text">{{item.text}}</view>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. props: {
  13. currentPage: {
  14. type: String,
  15. default: '/pages/tabBar/home'
  16. }
  17. },
  18. data () {
  19. return {
  20. tabBar: [{
  21. url: '/pages/tabBar/home',
  22. text: '首页',
  23. imgNormal: '/static/tabBar/home.png',
  24. imgClick: '/static/tabBar/home-active.png'
  25. },
  26. {
  27. url: '/pages/tabBar/giftPackageCenter',
  28. text: '礼包中心',
  29. imgNormal: '/static/tabBar/giftPackageCenter.png',
  30. imgClick: '/static/tabBar/giftPackageCenter-active.png'
  31. },
  32. {
  33. url: '/pages/tabBar/order',
  34. text: '订单',
  35. imgNormal: '/static/tabBar/order.png',
  36. imgClick: '/static/tabBar/order-active.png'
  37. },
  38. {
  39. url: '/pages/tabBar/mine',
  40. text: '我的',
  41. imgNormal: '/static/tabBar/mine.png',
  42. imgClick: '/static/tabBar/mine-active.png'
  43. }]
  44. };
  45. },
  46. created () {
  47. uni.hideTabBar({})
  48. },
  49. computed: {
  50. },
  51. methods: {
  52. navTo (item) {
  53. if (item.url !== this.currentPage) {
  54. var isUrl = item.url
  55. const that = this
  56. uni.switchTab({
  57. url: isUrl
  58. })
  59. } else {
  60. // this.$parent.toTop()
  61. }
  62. }
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. //导航栏设置
  68. $isRadius: 0upx; //左上右上圆角
  69. $isWidth: 100vw; //导航栏宽度
  70. $isBorder: 0px solid white; //边框 不需要则设为0px
  71. $isBg: #ffffff; //背景
  72. // 选中设置
  73. $chooseTextColor: #fb0b03; //选中时字体颜色
  74. $chooseBgColor: transparent; //选中时背景颜色 transparent为透明
  75. //未选中设置
  76. $normalTextColor: #1a1a1a; //未选中颜色
  77. .tabBar {
  78. width: $isWidth;
  79. height: 120upx;
  80. position: fixed;
  81. bottom: 0;
  82. left: 0;
  83. right: 0;
  84. margin: 0 auto;
  85. z-index: 998;
  86. background: $isBg;
  87. color: $normalTextColor;
  88. border-left: $isBorder;
  89. //border-top: 2rpx solid #e4e4e4;
  90. border-right: $isBorder;
  91. display: flex;
  92. justify-content: space-around;
  93. border-top-right-radius: $isRadius;
  94. border-top-left-radius: $isRadius;
  95. box-sizing: border-box;
  96. overflow: hidden;
  97. .tabbar_item {
  98. width: 25%;
  99. font-size: 12px;
  100. display: flex;
  101. flex-direction: column;
  102. justify-content: center;
  103. align-items: center;
  104. font-weight: bold;
  105. margin-bottom: 14rpx;
  106. &.active {
  107. border-left: $isBorder;
  108. border-top: $isBorder;
  109. background: $chooseBgColor;
  110. color: $chooseTextColor;
  111. font-weight: bold;
  112. }
  113. }
  114. image {
  115. width: 60rpx;
  116. height: 60rpx;
  117. margin-left: 5rpx;
  118. margin-bottom: 5rpx;
  119. }
  120. }
  121. </style>