tabbar.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <navBar :title='title' iconForce="false" ref="navbar">
  3. </navBar>
  4. <water/>
  5. <view>
  6. <template v-if="index==1">
  7. <home />
  8. </template>
  9. <template v-if="index==2">
  10. </template>
  11. <template v-if="index==3">
  12. <my />
  13. </template>
  14. <up-tabbar :value="index" :placeholder="false" @change="change">
  15. <up-tabbar-item text="首页" name='1'>
  16. <template #active-icon>
  17. <image style="width: 41rpx;height: 43rpx;" src="@/static/home1.png">
  18. </image>
  19. </template>
  20. <template #inactive-icon>
  21. <image style="width: 41rpx;height: 43rpx;" src="@/static/home2.png"></image>
  22. </template>
  23. </up-tabbar-item>
  24. <up-tabbar-item text="消息" name='2' :badge="unread>0?unread:false">
  25. <template #active-icon>
  26. <image style="width: 41rpx;height: 43rpx;" src="@/static/new1.png">
  27. </image>
  28. </template>
  29. <template #inactive-icon>
  30. <image style="width: 41rpx;height: 43rpx;" src="@/static/new2.png"></image>
  31. </template>
  32. </up-tabbar-item>
  33. <up-tabbar-item text="我的" name='3'>
  34. <template #active-icon>
  35. <image style="width: 41rpx;height: 43rpx;" src="@/static/my1.png">
  36. </image>
  37. </template>
  38. <template #inactive-icon>
  39. <image style="width: 41rpx;height: 43rpx;" src="@/static/my2.png"></image>
  40. </template>
  41. </up-tabbar-item>
  42. </up-tabbar>
  43. </view>
  44. </template>
  45. <script setup>
  46. import {
  47. onReady,
  48. onShow,
  49. onLoad
  50. } from '@dcloudio/uni-app'
  51. import {
  52. ref,
  53. reactive,
  54. getCurrentInstance,
  55. onMounted
  56. } from 'vue';
  57. import login from '../../api/model/login';
  58. const {
  59. proxy
  60. } = getCurrentInstance()
  61. import home from '@/pages/home/home.vue';
  62. import my from '@/pages/my/my.vue'
  63. const index = ref('1')
  64. const title = ref('首页')
  65. const navbar = ref()
  66. const unread = ref(0)
  67. const updateUnread = (e) => {
  68. unread.value = e
  69. }
  70. const change = (e) => {
  71. index.value = e
  72. switch (e) {
  73. case '1':
  74. title.value = '首页'
  75. navbar.value.changeTitle('首页')
  76. break
  77. case '2':
  78. title.value = '消息'
  79. navbar.value.changeTitle('消息')
  80. break
  81. case '3':
  82. title.value = '我的'
  83. navbar.value.changeTitle('我的')
  84. break
  85. }
  86. }
  87. onShow(() => {
  88. });
  89. onLoad((e) => {
  90. if (e && e.index == '2') {
  91. index.value = '2'
  92. }
  93. });
  94. onMounted(() => {
  95. if (index.value == '2') {
  96. change('2')
  97. }
  98. })
  99. </script>
  100. <style lang="scss" scoped>
  101. ::v-deep.uni-section__content-title {
  102. font-weight: bold;
  103. }
  104. ::v-deep.uni-section {
  105. width: 97%;
  106. margin: 20rpx auto;
  107. background-color: transparent;
  108. // position: absolute;
  109. // top: 310rpx;
  110. z-index: -1;
  111. // position: relative;
  112. }
  113. </style>