App.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div v-if="title != '/'" id="nav">
  3. <span class="back" @click="goBack"><nut-icon name="left"></nut-icon></span>
  4. {{ title }}
  5. </div>
  6. <router-view />
  7. </template>
  8. <script lang="ts">
  9. import { defineComponent, ref, watch } from 'vue';
  10. import { useRoute, useRouter } from 'vue-router';
  11. import { isMobile } from '@/sites/assets/util';
  12. export default defineComponent({
  13. name: 'app',
  14. setup() {
  15. const title = ref('NutUI');
  16. // 获取当前路由
  17. const route = useRoute();
  18. const router = useRouter();
  19. //返回demo页
  20. const goBack = () => {
  21. router.push('/');
  22. };
  23. // 当当前路由发生变化时,调用回调函数
  24. watch(
  25. () => route,
  26. () => {
  27. // const { origin, hash, pathname } = window.top.location;
  28. const { hash } = window.top.location;
  29. if (!isMobile && route.hash != hash) {
  30. // window.top.location.replace(`${origin}${pathname}#/${route.hash}`);
  31. title.value = route.name as string;
  32. } else {
  33. title.value = route.name as string;
  34. }
  35. },
  36. {
  37. immediate: true,
  38. deep: true
  39. }
  40. );
  41. return { title, goBack };
  42. }
  43. });
  44. </script>
  45. <style lang="scss">
  46. #app {
  47. background: #fff;
  48. height: 100%;
  49. width: 100%;
  50. display: flex;
  51. flex-direction: column;
  52. #nav {
  53. position: fixed;
  54. z-index: 10;
  55. left: 0;
  56. right: 0;
  57. height: 57px;
  58. line-height: 57px;
  59. text-align: center;
  60. background: $white;
  61. font-weight: bold;
  62. font-size: 20px;
  63. color: rgba(51, 51, 51, 1);
  64. box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.07);
  65. .back {
  66. position: absolute;
  67. left: 25px;
  68. }
  69. }
  70. .demo {
  71. height: 100%;
  72. background: #f7f8fa;
  73. overflow-x: hidden;
  74. overflow-y: auto;
  75. padding: 57px 25px 0 25px;
  76. &.full {
  77. padding: 57px 0 0 0;
  78. h2 {
  79. padding-left: 25px;
  80. }
  81. }
  82. &.bg-w {
  83. background: #fff;
  84. }
  85. &::-webkit-scrollbar {
  86. width: 0;
  87. background: transparent;
  88. }
  89. > h2 {
  90. margin-top: 30px;
  91. margin-bottom: 10px;
  92. font-size: 14px;
  93. color: rgba(144, 156, 164, 1);
  94. }
  95. > p {
  96. font-size: 12px;
  97. }
  98. .card {
  99. padding: 25px 18px;
  100. background: rgba(255, 255, 255, 1);
  101. }
  102. }
  103. }
  104. </style>