wd-root-portal.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <!-- #ifdef H5 -->
  3. <!-- H5端使用 teleport -->
  4. <teleport to="body">
  5. <!-- #endif -->
  6. <!-- #ifdef MP-WEIXIN || MP-ALIPAY -->
  7. <!-- #ifndef MP-DINGTALK -->
  8. <!-- 小程序使用 root-portal -->
  9. <root-portal>
  10. <!-- #endif -->
  11. <!-- #endif -->
  12. <slot />
  13. <!-- #ifdef MP-WEIXIN || MP-ALIPAY -->
  14. <!-- #ifndef MP-DINGTALK -->
  15. </root-portal>
  16. <!-- #endif -->
  17. <!-- #endif -->
  18. <!-- #ifdef H5 -->
  19. </teleport>
  20. <!-- #endif -->
  21. </template>
  22. <script>
  23. export default {
  24. name: 'wd-root-portal',
  25. options: {
  26. virtualHost: true,
  27. addGlobalClass: true,
  28. styleIsolation: 'shared'
  29. }
  30. }
  31. </script>
  32. <script lang="ts" setup></script>
  33. <!-- #ifdef APP-PLUS -->
  34. <script module="render" lang="renderjs">
  35. export default {
  36. mounted() {
  37. if (this.$ownerInstance.$el) {
  38. (document.querySelector('uni-app') || document.body).appendChild(this.$ownerInstance.$el)
  39. }
  40. },
  41. beforeDestroy() {
  42. // 清理,将元素移回原位置
  43. if (this.$ownerInstance.$el) {
  44. (document.querySelector('uni-app') || document.body).removeChild(this.$ownerInstance.$el)
  45. }
  46. }
  47. }
  48. </script>
  49. <!-- #endif -->