{"id":2834,"date":"2026-08-29T09:20:43","date_gmt":"2026-08-29T01:20:43","guid":{"rendered":"https:\/\/www.xfan.top\/?p=2834"},"modified":"2026-08-29T09:20:43","modified_gmt":"2026-08-29T01:20:43","slug":"vue-teleport%e5%ae%9e%e7%8e%b0%e8%84%b1%e7%a6%bb%e6%96%87%e6%a1%a3%e6%b5%81%e7%9a%84%e4%b8%8b%e6%8b%89%e9%9d%a2%e6%9d%bf","status":"publish","type":"post","link":"https:\/\/www.xfan.top\/index.php\/2026\/08\/29\/2834\/","title":{"rendered":"Vue Teleport\u5b9e\u73b0\u8131\u79bb\u6587\u6863\u6d41\u7684\u4e0b\u62c9\u9762\u677f"},"content":{"rendered":"<h2>\u6548\u679c\u9884\u89c8<\/h2>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.xfan.top\/wp-content\/uploads\/2025\/08\/QQ\u5f55\u5c4f20250804095525-1.gif'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/www.xfan.top\/wp-content\/uploads\/2025\/08\/QQ\u5f55\u5c4f20250804095525-1.gif\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h2>\u4e3b\u8981\u9700\u6c42<\/h2>\n<ol>\n<li>\u4e0b\u62c9\u9762\u677f\u5438\u9644\u81f3\u76f8\u5bf9\u67d0\u4e2a\u81ea\u5b9a\u4e49\u5143\u7d20\u7684\u4f4d\u7f6e\uff08\u4f8b\u5982\u76f8\u5bf9\u8f93\u5165\u6846+\u8f93\u5165\u6846\u9ad8\u5ea6\u7684\u4f4d\u7f6e\uff09\u3002<\/li>\n<li>\u4e0b\u62c9\u9762\u677f\u4e0d\u53d7\u5bb9\u5668\u7684<code>overflow<\/code>\u5f71\u54cd\uff08\u4e0b\u62c9\u9762\u677f\u4e0d\u80fd\u88ab<code>overflow:hidden<\/code>\u88c1\u526a\u6216\u5bfc\u81f4\u5bb9\u5668\u51fa\u73b0\u6eda\u52a8\u6761\uff09<\/li>\n<\/ol>\n<h2>Teleport \u76f8\u5173\u77e5\u8bc6<\/h2>\n<blockquote>\n<p><code>&lt;Teleport&gt;<\/code> \u662f\u4e00\u4e2a\u5185\u7f6e\u7ec4\u4ef6\uff0c\u5b83\u53ef\u4ee5\u5c06\u4e00\u4e2a\u7ec4\u4ef6\u5185\u90e8\u7684\u4e00\u90e8\u5206\u6a21\u677f\u201c\u4f20\u9001\u201d\u5230\u8be5\u7ec4\u4ef6\u7684 DOM \u7ed3\u6784\u5916\u5c42\u7684\u4f4d\u7f6e\u53bb\u3002<br \/>\n<a href=\"https:\/\/cn.vuejs.org\/guide\/built-ins\/teleport#basic-usage\">Vue\u6587\u6863\u4e2d\u7684\u8bf4\u660e<\/a><\/p>\n<\/blockquote>\n<h2>\u5b9e\u73b0\u7ec6\u8282<\/h2>\n<h4>\u4f7f\u4e0b\u62c9\u9762\u677f\u4e0d\u53d7\u5bb9\u5668<code>overflow<\/code>\u5f71\u54cd<\/h4>\n<p>\u4f7f\u7528<code>&lt;Teleport to=&quot;body&quot;&gt;&lt;\/Teleport&gt;<\/code> \u5305\u88f9\u4e0b\u62c9\u9762\u677f\u7684template\u90e8\u5206\u3002\u4e0b\u62c9\u9762\u677f\u7684dom\u76f4\u63a5\u6302\u8f7d\u5230body\u4e0b\uff0c\u8131\u79bb\u4e86\u5f53\u524d\u6587\u6863\u6d41\uff0c\u81ea\u7136\u4e0d\u53d7\u7236\u7ea7overflow\u5c5e\u6027\u7684\u5f71\u54cd\u3002<\/p>\n<h4>\u662f\u4e0b\u62c9\u9762\u677f\u5438\u9644\u81f3\u8f93\u5165\u6846\u7684\u5e95\u90e8<\/h4>\n<p>\u4e3a\u8f93\u5165\u6846\u7ed1\u5b9a\u6a21\u677f\u5f15\u7528\uff1a<\/p>\n<pre><code>&lt;a-input ref=&quot;Input&quot; \/&gt;<\/code><\/pre>\n<p>script setup\u4e2d\u83b7\u53d6\u6a21\u677f\u5f15\u7528\uff1a<\/p>\n<pre><code>const Input = ref();\n# \u6216 \u4e24\u79cd\u5199\u6cd5\u7b49\u540c\nconst Input = useTemplateRef(&quot;Input&quot;);<\/code><\/pre>\n<p>\u5b9e\u65f6\u83b7\u53d6\u8f93\u5165\u6846\u4f4d\u7f6e\uff1a<\/p>\n<pre><code>import { useElementBounding } from &quot;@vueuse\/core&quot;; # \u5efa\u8bae\u5b89\u88c5\u4f7f\u7528vueuse\n\nconst { top, left, height } = useElementBounding(Input);\n\nconst popupStyle = computed(() =&gt; ({\n  position: &quot;absolute&quot;,\n  top: top.value + height.value + &quot;px&quot;,\n  left: left.value + &quot;px&quot;,\n  zIndex: 9999,\n}));<\/code><\/pre>\n<p><code>top<\/code>\u3001<code>left<\/code>\u3001 <code>height<\/code>\u90fd\u662f\u54cd\u5e94\u5f0f\u5f15\u7528\uff0c\u4f1a\u968f\u7740Input\u5143\u7d20\u4f4d\u7f6e\u53d8\u5316\u800c\u53d8\u5316\uff08\u8fd9\u91cc\u6682\u4e0d\u8ba8\u8bba\u5b9e\u73b0\u65b9\u5f0f\uff0c\u662f\u6d4f\u89c8\u5668\u539f\u751fAPI\u529f\u80fd\uff09\u3002\u5728\u8ba1\u7b97\u5c5e\u6027\u4e2d\u6784\u5efa\u4e0b\u62c9\u9762\u677f\u7684CSS\u5c5e\u6027\uff0c\u7ed1\u5b9a\u5230\u4e0b\u62c9\u9762\u677f\u5143\u7d20\u4e0a\u5373\u53ef\u3002<\/p>\n<pre><code>&lt;div class=&quot;client-selecter&quot; :style=&quot;{ ...otherStyle, ...popupStyle }&quot; ...\n# \u591a\u4e2acss\u5c5e\u6027\u5bf9\u8c61\uff0c\u5efa\u8bae\u5c06popupStyle\u653e\u5728\u6700\u540e\uff0c\u91cd\u590d\u7684\u5c5e\u6027\u540e\u9762\u7684\u5c5e\u6027\u4f1a\u8986\u76d6\u524d\u9762\u7684<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6548\u679c\u9884\u89c8 \u4e3b\u8981\u9700\u6c42 \u4e0b\u62c9\u9762\u677f\u5438\u9644\u81f3\u76f8\u5bf9\u67d0\u4e2a\u81ea\u5b9a\u4e49\u5143\u7d20\u7684\u4f4d\u7f6e\uff08\u4f8b\u5982\u76f8\u5bf9\u8f93\u5165\u6846+\u8f93\u5165\u6846\u9ad8\u5ea6\u7684\u4f4d\u7f6e\uff09\u3002 \u4e0b\u62c9\u9762\u677f\u4e0d\u53d7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2834","post","type-post","status-publish","format-standard","hentry","category-webappdev"],"_links":{"self":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/comments?post=2834"}],"version-history":[{"count":4,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2834\/revisions"}],"predecessor-version":[{"id":2845,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2834\/revisions\/2845"}],"wp:attachment":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/media?parent=2834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/categories?post=2834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/tags?post=2834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}