ui-tab-bar.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div class="h-98rem">
  3. <van-tabbar class="h-98rem" v-model="active" safe-area-inset-bottom>
  4. <van-tabbar-item @click="tab.onClick" v-for="(tab, index) in tabList" :key="index">
  5. <template #icon="props">
  6. <div class="flex items-center flex-col">
  7. <img class="w-60rem h-60rem object-contain"
  8. :src="props.active ? tab.activeIcon : tab.activeIcon" />
  9. <span
  10. :class="`${props.active ? 'text-primary' : 'text-[#010101]'} text-size-20rem`">{{tab.title}}</span>
  11. </div>
  12. </template>
  13. </van-tabbar-item>
  14. </van-tabbar>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. currentPath: this.$route.path,
  22. tabList: [
  23. {
  24. icon: '/imgs/tab-home.png',
  25. activeIcon: '/imgs/tab-home-checked.png',
  26. title: '首页',
  27. onClick: () => {
  28. this.$router.push("/home")
  29. }
  30. },
  31. {
  32. icon: '/imgs/tab-publish.png',
  33. activeIcon: '/imgs/tab-publish-checked.png',
  34. title: '投稿',
  35. onClick: () => {
  36. this.$router.push("/publish")
  37. }
  38. },
  39. {
  40. icon: '/imgs/tab-aboutus.png',
  41. activeIcon: '/imgs/tab-aboutus-checked.png',
  42. title: '关于我们',
  43. onClick: () => {
  44. this.$router.push("/aboutus")
  45. }
  46. },
  47. {
  48. icon: '/imgs/tab-user.png',
  49. activeIcon: '/imgs/tab-user-checked.png',
  50. title: '我的',
  51. onClick: () => {
  52. this.$router.push("/user")
  53. }
  54. },
  55. ]
  56. }
  57. },
  58. watch: {
  59. $route: function (next) {
  60. this.currentPath = next.path;
  61. },
  62. },
  63. computed: {
  64. active: (vm) => {
  65. const routes = ['/home', '/publish', '/aboutus', '/user']
  66. return routes.findIndex(path => path === vm.currentPath)
  67. }
  68. }
  69. }
  70. </script>