index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="tarbar">
  3. <view class=".tarbar-list" :style="{
  4. 'border-top': tabBar.position == 'bottom' ? '1rpx solid ' + tabBar.borderStyle : 0,
  5. 'border-bottom': tabBar.position == 'top' ? '1rpx solid ' + tabBar.borderStyle : 0,
  6. background: tabBar.backgroundColor,
  7. color: tabBar.color
  8. }">
  9. <view class="tarbar-list-ul">
  10. <view class="tarbar-list-li" v-for="(item, index) in list" :key="index" @click.stop="setSelected(index)">
  11. <block>
  12. <view class="tarbar-list-li-icon">
  13. <image :src="selected == index ? item.selectedIconPath : item.iconPath"></image>
  14. </view>
  15. <view :style='selected == index?"color:"+tabBar.selectedColor:""' class="tarbar-list-li-name">{{ item.text }}</view>
  16. </block>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. tabBar: {
  27. "color":"#99999",
  28. "selectedColor":"#3384ff",
  29. "borderStyle": "white",
  30. "backgroundColor": "#ffffff",
  31. "position": 'bottom'
  32. },
  33. selected: this.current //当前激活项
  34. };
  35. },
  36. props: {
  37. current: {
  38. type: [Number, String],
  39. default: 0
  40. },
  41. list:{
  42. type:[Array],
  43. default:()=>[]
  44. }
  45. },
  46. watch:{
  47. current(index){
  48. if (this.selected == index) return
  49. this.selected=index;
  50. let title=this.list[index].text;
  51. uni.setNavigationBarTitle({
  52. title
  53. })
  54. }
  55. },
  56. methods: {
  57. setSelected(index) {
  58. this.$emit('change', index)
  59. },
  60. }
  61. }
  62. </script>
  63. <style>
  64. .tarbar {
  65. width: 100%;
  66. z-index: 9999;
  67. position: fixed;
  68. bottom: 0;
  69. background-color: #fff;
  70. }
  71. .tarbar-list {
  72. width: 100%;
  73. height: 98upx;
  74. background: #4d586f;
  75. position: fixed;
  76. left: 0;
  77. bottom: 0;
  78. }
  79. .tarbar-list-ul {
  80. width: 100%;
  81. height: 100%;
  82. padding: 0upx 60upx;
  83. display: flex;
  84. justify-content: space-between;
  85. box-sizing: border-box;
  86. }
  87. .tarbar-list-li {
  88. width: 80upx;
  89. height: 100%;
  90. display: flex;
  91. flex-direction: column;
  92. justify-content: center;
  93. align-items: center;
  94. }
  95. .tarbar-list-li-icon {
  96. width: 50upx;
  97. height: 50upx;
  98. margin: 0 auto;
  99. display: flex;
  100. align-items: center;
  101. justify-content: center;
  102. }
  103. .tarbar-list-li-icon image {
  104. width: 50rpx;
  105. height: 50rpx;
  106. }
  107. .tarbar-list-li-name {
  108. width: 100%;
  109. text-align: center;
  110. line-height: 30upx;
  111. font-size: 24upx;
  112. height: 30upx;
  113. padding: 12upx 0 2upx 0;
  114. }
  115. .tarbar-list-li-center {
  116. width: 100upx;
  117. }
  118. </style>