fg-tabbar.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <template>
  2. <wd-tabbar
  3. fixed
  4. v-model="tabbarStore.curIdx"
  5. bordered
  6. safeAreaInsetBottom
  7. placeholder
  8. @change="selectTabBar"
  9. >
  10. <block v-for="(item, idx) in tabbarList" :key="item.path">
  11. <wd-tabbar-item v-if="item.isUnocssIcon" :title="item.text">
  12. <template #icon>
  13. <view
  14. h-40rpx
  15. w-40rpx
  16. :class="[item.icon, idx === tabbarStore.curIdx ? 'is-active' : 'is-inactive']"
  17. ></view>
  18. </template>
  19. </wd-tabbar-item>
  20. <wd-tabbar-item v-else :title="item.text" :icon="item.icon"></wd-tabbar-item>
  21. </block>
  22. </wd-tabbar>
  23. </template>
  24. <script setup lang="ts">
  25. import { tabBar } from '@/pages.json'
  26. import { tabbarStore } from './tabbar'
  27. /** tabbarList 里面的 path 必须和 pages.config.ts 的页面路径一致 */
  28. const tabbarList = tabBar.list.map((item) => ({ ...item, path: `/${item.pagePath}` }))
  29. function selectTabBar({ value: index }: { value: number }) {
  30. const url = tabbarList[index].path
  31. tabbarStore.setCurIdx(index)
  32. uni.switchTab({ url })
  33. }
  34. </script>