index.vue 558 B

12345678910111213141516171819202122232425262728
  1. <template>
  2. <Suspense v-if="isBody">
  3. <Teleport to="#hc-header-page-name">
  4. <div class="hc-header-page-extra">
  5. <slot></slot>
  6. </div>
  7. </Teleport>
  8. </Suspense>
  9. </template>
  10. <script setup>
  11. import {nextTick, ref} from "vue";
  12. const isBody = ref(false)
  13. //渲染完成
  14. nextTick(()=> {
  15. //页面渲染完成后,再让 vue3 的 Teleport,挂载到指定节点
  16. isBody.value = true
  17. })
  18. </script>
  19. <style lang="scss">
  20. .hc-header-page-extra {
  21. position: relative;
  22. margin-left: 24px;
  23. }
  24. </style>