demo.vue 612 B

123456789101112131415161718192021222324252627282930313233
  1. <template>
  2. <Teleport to="body">
  3. <div class="demo">
  4. <h1>demo</h1>
  5. <button @click="isShow = true">开启弹框</button>
  6. <button @click="isShow = false">关闭弹框</button>
  7. <div class="dialog" v-if="isShow"></div>
  8. </div>
  9. </Teleport>
  10. </template>
  11. <script lang="ts" setup>
  12. import {ref,reactive} from "vue"
  13. let isShow = ref(false)
  14. </script>
  15. <style scoped>
  16. .demo {
  17. width: 400px;
  18. height: 400px;
  19. background: skyblue;
  20. position: absolute;
  21. top: 50%;
  22. left: 50%;
  23. margin-left: -200px;
  24. margin-top: -200px;
  25. }
  26. .dialog{
  27. width: 100px;
  28. height: 100px;
  29. background: #00f;
  30. }
  31. </style>