tab-bar.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view class="tab-bar-wrapper">
  3. <view class="tab-bar">
  4. <view class="tab-item" :class="{active:active===0}" @click="onClick(0)">
  5. <view class="image">
  6. </view>
  7. <view class="text">
  8. 首页
  9. </view>
  10. </view>
  11. <view class="tab-item" :class="{active:active===1}" @click="onClick(1)">
  12. <view class="image">
  13. </view>
  14. <view class="text">
  15. 我的
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'TabBar',
  24. props: {
  25. active: {
  26. type: Number,
  27. default: 0
  28. }
  29. },
  30. methods: {
  31. onClick(i) {
  32. i !== this.active &&
  33. uni.redirectTo({
  34. url: i === 0 ? '/pages/task/task1' : '/pages/user/user1',
  35. fail(e) {
  36. console.log(e)
  37. },
  38. complete(e) {
  39. console.log(e)
  40. }
  41. })
  42. }
  43. }
  44. }
  45. </script>
  46. <style lang="scss" scoped>
  47. .tab-bar-wrapper {
  48. height: 100rpx;
  49. position: fixed;
  50. left: var(--window-left);
  51. right: var(--window-right);
  52. bottom: 0;
  53. color: #C0C4CC;
  54. background-color: #fff;
  55. font-size: 20rpx;
  56. }
  57. .tab-bar {
  58. display: flex;
  59. }
  60. .tab-item {
  61. flex: 1;
  62. display: flex;
  63. flex-direction: column;
  64. justify-content: center;
  65. align-items: center;
  66. .image {
  67. width: 48rpx;
  68. height: 48rpx;
  69. background-image: url('../static/tabbar/home.png');
  70. background-size: cover;
  71. }
  72. }
  73. .tab-item:nth-child(2) {
  74. .image {
  75. background-image: url('../static/tabbar/mine.png');
  76. }
  77. }
  78. .tab-item.active {
  79. color: #000;
  80. .image {
  81. background-image: url('../static/tabbar/home_active.png');
  82. }
  83. }
  84. .tab-item:nth-child(2).active {
  85. .image {
  86. background-image: url('../static/tabbar/mine_active.png');
  87. }
  88. }
  89. </style>