App.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <router-view v-slot="{ Component }">
  3. <keep-alive include="Home">
  4. <component :is="Component" />
  5. </keep-alive>
  6. </router-view>
  7. </template>
  8. <script setup lang="ts">
  9. import { onMounted, onBeforeUnmount, watch, computed } from 'vue';
  10. import { useRouter } from 'vue-router';
  11. const router = useRouter();
  12. const handleLinkClick = (e: MouseEvent) => {
  13. const target = (e.target as HTMLElement).closest('a') as HTMLAnchorElement | null;
  14. if (target && target.tagName === 'A' && target.href) {
  15. e.preventDefault();
  16. window.open(target.href, '_blank', 'noopener,noreferrer');
  17. }
  18. };
  19. onMounted(() => {
  20. if (location.pathname !== '/') {
  21. router.push('/');
  22. }
  23. document.addEventListener('click', handleLinkClick);
  24. });
  25. onBeforeUnmount(() => {
  26. document.removeEventListener('click', handleLinkClick);
  27. });
  28. </script>
  29. <style>
  30. /* 全局样式 */
  31. .help-tip {
  32. width: 540px;
  33. /* height: 110px; */
  34. display: flex;
  35. flex-direction: column;
  36. /* box-sizing: border-box; */
  37. padding: 20px 20px !important;
  38. .title {
  39. font-weight: bold;
  40. font-size: 16px;
  41. color: #282e30;
  42. margin-bottom: 10px;
  43. }
  44. .value {
  45. font-weight: 400;
  46. font-size: 14px;
  47. color: #282e30;
  48. }
  49. }
  50. </style>