BottomNav.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div class="bottom-nav">
  3. <a v-for="item in menuList" :key="item.path" :class="{ 'active': activeIndex === item.path }"
  4. @click.prevent="setActiveIndex(item.path)">
  5. <van-icon style="margin-bottom: 5px;" :name="item.icon"
  6. :color="activeIndex === item.path ? '#007BFF' : '#fff'" size="1.3rem" />
  7. {{ item.name }}
  8. </a>
  9. </div>
  10. </template>
  11. <script setup>
  12. import { ref } from 'vue';
  13. import { useRouter, useRoute } from 'vue-router';
  14. const menuList = [
  15. { name: '首页', icon: 'wap-home-o', path: '/home' },
  16. { name: '一张图', icon: 'location-o', path: '/map' },
  17. { name: '督查', icon: 'completed-o', path: '/inspect' },
  18. { name: '问题', icon: 'orders-o', path: '/question' },
  19. { name: '我的', icon: 'user-o', path: '/about' },
  20. ]
  21. const route = useRoute();
  22. const router = useRouter();
  23. // 定义当前激活的导航索引
  24. const activeIndex = ref(route.path);
  25. // 定义设置激活索引的方法
  26. const setActiveIndex = (path) => {
  27. activeIndex.value = path;
  28. router.push(path);
  29. };
  30. </script>
  31. <style lang="scss" scoped>
  32. .bottom-nav {
  33. display: flex;
  34. justify-content: space-around;
  35. background-color: #333;
  36. color: white;
  37. // padding: 10px 0;
  38. position: fixed;
  39. bottom: 0;
  40. left: 0;
  41. right: 0;
  42. }
  43. .bottom-nav a {
  44. color: white;
  45. text-decoration: none;
  46. padding: 8px;
  47. display: flex;
  48. flex-direction: column;
  49. align-items: center;
  50. font-size: .7rem;
  51. border-radius: 10px;
  52. }
  53. .bottom-nav a.active {
  54. color: #007BFF;
  55. }
  56. </style>