MTeleport.vue 445 B

1234567891011121314151617181920212223242526272829
  1. <template>
  2. <div>
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: "teleport",
  9. props: {
  10. to: {
  11. type: String,
  12. required: true,
  13. },
  14. },
  15. mounted() {
  16. const toEl = document.querySelector(this.to);
  17. if (toEl) {
  18. toEl.appendChild(this.$el);
  19. }
  20. },
  21. destroyed() {
  22. const toEl = document.querySelector(this.to);
  23. if (toEl) {
  24. toEl.removeChild(this.$el);
  25. }
  26. },
  27. };
  28. </script>