hans-tabbar.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. if (index === this.current) {
  29. return;
  30. }
  31. this.current = index;
  32. this.$emit('tabChange',index)
  33. }
  34. }
  35. };
  36. </script>
  37. <style lang="scss" scoped >
  38. .weui-tabbar {
  39. display: flex;
  40. position: relative;
  41. z-index: 500;
  42. background-color: #ffffff;
  43. }
  44. .weui-tabbar:before {
  45. content: ' ';
  46. position: absolute;
  47. left: 0;
  48. top: 0;
  49. right: 0;
  50. height: 1px;
  51. border-top: 1rpx solid rgba(0, 0, 0, 0.1);
  52. color: rgba(0, 0, 0, 0.1);
  53. }
  54. .weui-tabbar__item {
  55. display: block;
  56. flex: 1;
  57. padding: 8px 0 4px;
  58. // padding-bottom: calc(8px + constant(safe-area-inset-bottom));
  59. // padding-bottom: calc(8px + env(safe-area-inset-bottom));
  60. font-size: 0;
  61. color: rgba(0, 0, 0, 0.5);
  62. text-align: center;
  63. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  64. }
  65. .weui-tabbar__item:first-child {
  66. padding-left: constant(safe-area-inset-left);
  67. padding-left: env(safe-area-inset-left);
  68. }
  69. .weui-tabbar__item:last-child {
  70. padding-right: constant(safe-area-inset-right);
  71. padding-right: env(safe-area-inset-right);
  72. }
  73. .weui-tabbar__item.weui-bar__item_on .weui-tabbar__icon,
  74. .weui-tabbar__item.weui-bar__item_on .weui-tabbar__icon > i,
  75. .weui-tabbar__item.weui-bar__item_on .weui-tabbar__label {
  76. color: #26D18B;
  77. }
  78. .weui-tabbar__icon {
  79. display: inline-block;
  80. width: 28px;
  81. height: 28px;
  82. margin-bottom: 2px;
  83. }
  84. i.weui-tabbar__icon,
  85. .weui-tabbar__icon > i {
  86. font-size: 24px;
  87. color: rgba(0, 0, 0, 0.5);
  88. }
  89. .weui-tabbar__icon image {
  90. width: 100%;
  91. height: 100%;
  92. }
  93. .weui-tabbar__label {
  94. color: #bfbfbf;
  95. font-size: 10px;
  96. line-height: 1.4;
  97. }
  98. </style>