hans-tabbar.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view class="weui-tabbar" :class="extClass">
  3. <!-- 选中的时候往weui-tabbar__item加class:weui-bar__item_on -->
  4. <view @click="tabChange(index)" v-for="(item, index) in list" :key="index" class="weui-tabbar__item" :class="{'weui-bar__item_on':index === current}">
  5. <view style="position: relative;display:inline-block;"><image :src="current === index ? item.selectedIconPath : item.iconPath" class="weui-tabbar__icon"></image></view>
  6. <view class="weui-tabbar__label">{{ item.text }}</view>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. props: {
  13. list: {
  14. type: Array,
  15. default: function() {
  16. return []
  17. }
  18. }
  19. },
  20. data() {
  21. return {
  22. extClass: '',
  23. current: 1
  24. };
  25. },
  26. methods: {
  27. tabChange(index) {
  28. console.log("taprouterIndex",index)
  29. console.log("routerAcIndex",this.current)
  30. if (index === this.current) {
  31. return;
  32. }
  33. this.current = index;
  34. this.$emit('tabChange',index)
  35. }
  36. }
  37. };
  38. </script>
  39. <style lang="scss" scoped >
  40. .weui-tabbar {
  41. display: flex;
  42. position: relative;
  43. z-index: 500;
  44. background-color: #ffffff;
  45. }
  46. .weui-tabbar:before {
  47. content: ' ';
  48. position: absolute;
  49. left: 0;
  50. top: 0;
  51. right: 0;
  52. height: 1px;
  53. border-top: 1rpx solid rgba(0, 0, 0, 0.1);
  54. color: rgba(0, 0, 0, 0.1);
  55. }
  56. .weui-tabbar__item {
  57. display: block;
  58. flex: 1;
  59. padding: 8px 0 4px;
  60. // padding-bottom: calc(8px + constant(safe-area-inset-bottom));
  61. // padding-bottom: calc(8px + env(safe-area-inset-bottom));
  62. font-size: 0;
  63. color: rgba(0, 0, 0, 0.5);
  64. text-align: center;
  65. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  66. }
  67. .weui-tabbar__item:first-child {
  68. padding-left: constant(safe-area-inset-left);
  69. padding-left: env(safe-area-inset-left);
  70. }
  71. .weui-tabbar__item:last-child {
  72. padding-right: constant(safe-area-inset-right);
  73. padding-right: env(safe-area-inset-right);
  74. }
  75. .weui-tabbar__item.weui-bar__item_on .weui-tabbar__icon,
  76. .weui-tabbar__item.weui-bar__item_on .weui-tabbar__icon > i,
  77. .weui-tabbar__item.weui-bar__item_on .weui-tabbar__label {
  78. color: #26D18B;
  79. }
  80. .weui-tabbar__icon {
  81. display: inline-block;
  82. width: 28px;
  83. height: 28px;
  84. margin-bottom: 2px;
  85. }
  86. i.weui-tabbar__icon,
  87. .weui-tabbar__icon > i {
  88. font-size: 24px;
  89. color: rgba(0, 0, 0, 0.5);
  90. }
  91. .weui-tabbar__icon image {
  92. width: 100%;
  93. height: 100%;
  94. }
  95. .weui-tabbar__label {
  96. color: #bfbfbf;
  97. font-size: 10px;
  98. line-height: 1.4;
  99. }
  100. </style>