CustomTabBar.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <view class="fixed bottom-0 left-0 right-0 z-999 bg-white b-t border-gray-200 flex h-100rpx">
  3. <view
  4. class="flex-1 flex flex-col items-center justify-center"
  5. v-for="(item, index) in tabs"
  6. :key="index"
  7. @click="switchTab(item, index)"
  8. >
  9. <image
  10. class="w-50rpx h-50rpx mb-4rpx"
  11. :src="current === index ? item.selectedIcon : item.icon"
  12. />
  13. <text :class="current === index ? 'text-blue-4' : 'text-gray-500'">
  14. {{ item.text }}
  15. </text>
  16. </view>
  17. </view>
  18. </template>
  19. <script setup>
  20. const props = defineProps({
  21. current: {
  22. type: Number,
  23. default: 0
  24. }
  25. })
  26. const emit = defineEmits(['change'])
  27. const tabs = [
  28. {
  29. text: '首页',
  30. pagePath: '/pages/index/index',
  31. icon: '/static/home.png',
  32. selectedIcon: '/static/home-selected.png'
  33. },
  34. {
  35. text: '我的',
  36. pagePath: '/pages/my/index',
  37. icon: '/static/my.png',
  38. selectedIcon: '/static/my-selected.png'
  39. }
  40. ]
  41. const switchTab = (item, index) => {
  42. emit('change', index)
  43. uni.redirectTo({url: item.pagePath, animationType: 'none'})
  44. }
  45. </script>
  46. <style scoped>
  47. /* 如果你的 UnoCSS 未启用 rpx 转换,可以保留不动 */
  48. </style>