main.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <script setup>
  2. import { ref, watch } from 'vue';
  3. import { RouterView, useRoute, useRouter } from 'vue-router';
  4. import { AccountBookOutlined, TeamOutlined, TrophyOutlined, BookOutlined } from '@ant-design/icons-vue';
  5. // 获取当前路由和路由实例
  6. const route = useRoute();
  7. const router = useRouter();
  8. const current = ref([route.name]);
  9. // 监听路由变化,更新选中菜单
  10. watch(() => route.name, (newName) => {
  11. current.value = [newName];
  12. });
  13. // 处理菜单点击事件
  14. const handleMenuClick = (e) => {
  15. const key = e.key;
  16. router.push({ name: key });
  17. };
  18. </script>
  19. <template>
  20. <a-menu v-model:selectedKeys="current" mode="horizontal" @click="handleMenuClick">
  21. <a-menu-item key="home">
  22. <template #icon>
  23. <account-book-outlined />
  24. </template>
  25. 策略
  26. </a-menu-item>
  27. <a-menu-item key="leagues">
  28. <template #icon>
  29. <team-outlined />
  30. </template>
  31. 联赛
  32. </a-menu-item>
  33. <a-menu-item key="games">
  34. <template #icon>
  35. <trophy-outlined />
  36. </template>
  37. 比赛
  38. </a-menu-item>
  39. <a-menu-item key="locales">
  40. <template #icon>
  41. <book-outlined />
  42. </template>
  43. 翻译
  44. </a-menu-item>
  45. </a-menu>
  46. <router-view />
  47. </template>
  48. <style scoped>
  49. </style>