蓝色天空网mbsky.com · 知识 · 实践 · 创造Vue3 · 本地阅读预览
教程 / 前端开发 / Vue3

Vue3 简介

系统梳理 Vue 3 架构重写、Proxy 响应式、组合式 API、Composables、内置组件、生命周期、TypeScript 支持、生态演进与框架边界,并以本地 Chromium 实测核心能力。

本站独立整理的内容草稿。实例显示的是预期结果;浏览器、服务端运行与技术内容验收尚待完成,本页只用于阅读和图文核对。

学完这一章,你能够

Vue 3 架构定位与与 Vue 2 的本质差异

Vue 3 由尤雨溪主导开发,于 2020 年 9 月 18 日发布(代号 One Piece)。它定位为易上手且能支撑复杂工程的渐进式前端框架:既可嵌入局部页面增强交互,也能构建完整 SPA 与 SSR 应用,在易用性与工程能力间保持均衡,同时通过 `Proxy` 响应式、组合式 API、TypeScript 原生重写与 Tree-shaking 实现全面革新。

相较 Vue 2,Vue 3 并非局部修补而是底层架构重写,涵盖响应机制、代码组织、类型推导、产物裁剪、运行时性能、多根节点模板及 `createApp` 实例隔离等七个核心维度,详细对照见下方对比表。

核心特性:组合式 API、Proxy 响应式与 Composables

Vue 3 的改进贯穿响应式系统、API 形态、编译器与内置组件四个方面。组合式 API(Composition API)解决了选项式 API 中同一业务被拆散到 `data`、`methods`、`computed`、`watch` 的痛点,让逻辑按功能聚合;配合单文件组件语法糖 `<script setup>`,顶层声明的响应式变量与函数会自动暴露给模板而无需手动 `return`,成为当前推荐写法。

在响应式底层,Vue 3 用 ES6 `Proxy` 替代了 Vue 2 的 `Object.defineProperty`,原生支持拦截对象新增属性与数组索引直接赋值。本站离线 Chromium 实测(`proxy_vs_defineproperty_reactivity`)验证:`Object.defineProperty` 漏掉了新增的 `user.email` 写入,而 `Proxy` 完整捕获 `email=dev@example.com` 与 `skills[0]='vue3'`,同时 `ref` 监听器准确记录 `count` 从 `0->10` 的变化。

可组合函数(Composables)约定以 `use` 为前缀,将有状态响应式逻辑抽离为跨组件复用的纯函数。本站实测(`composition_api_and_composable`)运行 `useCounter(10)`:两次递增渲染 `count=12,doubled=24`,递减后为 `count=11,doubled=22`,重置回到 `count=10,doubled=20`,且第二个 `createApp(0)` 实例保持独立状态 `count=1,doubled=2`。

新内置组件、Tree-shaking、生命周期与 TypeScript

Vue 3 新增 `Fragment`、`Teleport`、`Suspense` 三个内置组件以应对多根节点、跨层叠上下文弹窗与异步加载占位场景。本站 Chromium 实测(`fragment_teleport_suspense_dom`)验证:Fragment 直接挂载 `HEADER` 与 `MAIN` 两个并列节点;Teleport 将弹窗节点挂入 `BODY` 脱离 `overflow:hidden` 父容器;Suspense 先渲染 `加载中...` 占位,待异步 Promise 完成后切换为 `异步用户资料已就绪`。

全部全局 API 改为具名导出后,构建器可通过 Tree-shaking 剔除未引用函数。本站静态导入分析(`ts_sfc_and_treeshaking_analysis`)核验:从 10 个导出中仅按需导入 `ref`、`computed`、`watch`、`nextTick`、`onMounted` 5 项时,其余 5 项可在打包阶段安全裁剪。

组合式生命周期钩子统一以 `on` 开头并在 `setup` 阶段注册,`beforeCreate` 与 `created` 直接由 `setup` 自身替代,销毁阶段更名为 `onBeforeUnmount` 与 `onUnmounted`。本站 Chromium 实测(`lifecycle_hooks_sequence`)按序记录了全部 7 步钩子,并验证 `onUnmounted` 清除定时器后计数不再增长。

Vue 3 核心库以 TypeScript 重写,在 `<script setup lang="ts">` 中可直接定义接口并用泛型宏 `defineProps<...>()`、`defineEmits<...>()` 获得精确类型检查;实测静态解析准确提取 `lang="ts"`、`interface User` 及两项类型宏声明。

应用领域与主流 UI 组件库生态

依托完整生态,Vue 3 广泛覆盖单页应用(Vue Router 4 + Pinia,适用于后台管理、数据大屏与电商前台)以及基于 Nuxt 3 的服务端渲染(SSR)与静态站点生成(SSG,适合内容站、文档与营销页)。

在跨端与桌面端方向,uni-app 与 Ionic + Vue 3 支撑小程序、H5 与移动 App 开发,Electron + Vue 3 与轻量 Rust 后端的 Tauri + Vue 3 则支撑跨平台桌面客户端;配合 Element Plus、Ant Design Vue、Vant 4、Vuetify 3、Naive UI、shadcn-vue 等组件库可快速交付界面。

发展历程、三大框架对比与技术边界

Vue 起源于 2013 年尤雨溪对轻量数据驱动视图的探索,2014 年 2 月发布 0.8.0;2015 年 10 月 Vue 1.0(Evangelion)及 Router/Vuex/CLI 形成框架体系;2016 年 10 月 Vue 2.0 引入虚拟 DOM 与 SSR 并迎来生态高速扩张,2019 年 2 月 Vue 2.6(Macross)承前启后。

2018 年底启动的 Vue 3 历经约两年、30 余项 RFC 与多方协作于 2020 年 9 月 18 日正式发布,集中落地 Proxy 响应式、Composition API、TypeScript、Fragment/Teleport/Suspense 与 Tree-shaking。随后 3.2 至 3.5 持续完善 `<script setup>`、Pinia 默认推荐、`defineModel`、响应式 Props 解构与懒水合;面向未来的 Vapor Mode 通过编译时静态分析跳过虚拟 DOM 直接生成原生 DOM 更新,可与现有虚拟 DOM 模式共存并支持 `<script setup>` 渐进迁移。

与 React 18+ 和 Angular 17+ 相比,Vue 3 以直观的单文件组件模板、平缓学习曲线与完善的中文文档在国内企业项目中占据高采用率;同时团队也需正视双 API 风格统一、`.value` 习惯适应、超大型状态拆分、SSR 水合开销及英文社区相对规模等局限,结合规范与新版本特性理性选型。

Vue 2 与 Vue 3 核心架构对比

对比项Vue 2Vue 3
响应式原理基于 Object.defineProperty,难以直接追踪新增属性与数组索引赋值基于 ES6 Proxy,完整代理属性新增、删除与数组索引变更
代码组织方式以 Options API 为主,data/methods/computed 按选项拆分新增 Composition API,按业务关注点聚合逻辑并便于抽离复用
TypeScript 支持后期补充类型适配,复杂推导受限核心源码完全使用 TypeScript 重写,原生支持泛型宏与精准推导
包体积运行时约 20KB(gzip),全局挂载难以裁剪具名导出配合 Tree-shaking 按需打包,最小核心可降至约 13.5KB
性能以 Vue 2 运行时为历史基线官方基准显示初次渲染约提速 55%、更新约提速 133%、内存约降 54%
组件模板根节点单文件模板仅允许单一根元素包裹原生支持 Fragment 多根节点模板,减少多余 DOM 层级
全局 API挂载在全局 Vue 构造函数,多实例易共享污染通过 createApp 创建隔离应用实例,配置与状态互不干扰

Vue 3 新增内置组件对比

组件解决的问题典型使用场景
Fragment解除单根节点约束,允许组件模板直接返回多个并列顶层节点表格行、列表项组件及精简 DOM 层级
Teleport将模板子树传送挂载到指定 DOM 容器(如 body),绕开父级 overflow/z-index 限制全局弹窗 Modal、通知 Toast、悬浮工具条
Suspense在异步依赖完成前统一展示 fallback 占位内容,就绪后切换正式视图异步组件骨架屏、路由切换 Loading 状态

Vue 2 选项式与 Vue 3 组合式生命周期对照

Vue 2 选项式Vue 3 组合式触发时机
beforeCreate由 setup 本身直接替代组件实例初始化前
created由 setup 本身直接替代响应式状态创建完成时
beforeMountonBeforeMountDOM 首次挂载之前
mountedonMountedDOM 挂载完成后,可安全访问真实节点
beforeUpdateonBeforeUpdate响应式数据变更、DOM 补丁更新前
updatedonUpdatedDOM 重渲染更新完成后
beforeDestroyonBeforeUnmount组件实例卸载销毁前(名称调整)
destroyedonUnmounted组件卸载完成后,适合清理定时器与监听

Vue 3 主流 UI 组件库生态

组件库定位适用场景
Element Plus面向桌面端 PC 的成熟 Vue 3 组件库(Element UI 演进版)企业中后台与表单密集型系统
Ant Design Vue遵循 Ant Design 视觉与交互体系的 Vue 实现规范化中后台与企业级 Web 应用
Vant 4轻量高性能移动端 Vue 3 组件库移动端 H5 页面与小程序业务
Vuetify 3基于 Material Design 设计语言的组件生态面向终端消费者的跨屏 Web 应用
Naive UI全 TypeScript 编写且主题系统灵活的组件库强调类型安全与深度视觉定制的项目
shadcn-vue结合 Radix Vue 与 Tailwind 的源码可拷贝组件集合追求定制化 UI 与代码自主可控的项目

Vue 3 生态完善里程碑(2021–2022)

时间版本 / 事件里程碑意义
2021-08Vue 3.2<script setup> 与 <style> v-bind 正式稳定,大幅提升单文件开发体验
2022-02Vue 3 成为默认版本官网与 npm vue 默认标签切换至 3.x,Vue 3 成为生态主线
2022-05Pinia 成为官方推荐Pinia 正式接棒成为 Vue 3 官方推荐状态管理方案
2022Vue 3.3增强泛型组件与 defineProps 类型推导,优化 TypeScript 工程体验

Vue 3 持续优化里程碑(2023–2025)

时间版本重要特性
2023-12Vue 3.4重写模板解析器提速约 2 倍、优化响应式调度并稳定 defineModel 宏
2024-09Vue 3.5稳定响应式 Props 解构,新增 useTemplateRef 与 SSR 懒加载水合
2025(开发中)Vue 3.6集成 Alien Signals 降低依赖追踪内存,推进无虚拟 DOM 的 Vapor Mode Alpha

三大主流前端框架定位对比

对比维度Vue 3React 18+Angular 17+
定位渐进式框架,官方维护路由与状态管理专注视图层的 UI 库,生态由社区主导全功能企业级框架,内置完整工程方案
语法风格单文件组件(.vue)配合直观 HTML 模板JSX 语法,在 JavaScript 中编写视图组件模板加装饰器与强约定架构
学习曲线较平缓,贴近原生 HTML/CSS/JS 心智中等,需掌握 JSX 与 Hooks 规则较陡峭,涵盖依赖注入、RxJS 等概念
TypeScript核心 TS 重写,SFC 类型支持完善配合类型包支持良好默认采用 TypeScript 并深度集成
性能细粒度响应式精确触发更新结合 React 19 Compiler 持续优化引入 Signals 持续改进变更检测
适用规模覆盖小型原型到大型复杂应用各类规模及超大型前端项目均成熟偏重规范严谨的大型企业级项目
中国市场占有率国内采用率领先,中文文档与组件库完备采用率高,互联网与跨国团队常见国内采用比例相对较低

Vue 3 常见局限与应对建议

局限具体表现应对建议
Options API 与 Composition API 并存带来的决策成本两套风格并存容易造成团队代码规范不统一新项目统一约定 <script setup> 与组合式 API
响应式数据的 .value 心智负担ref 在脚本需读写 .value 而模板自动解包,初学者易遗漏启用 Vue Official (Volar) 插件自动补全并形成统一编码习惯
大型应用状态管理复杂度超大型高并发状态编排下需额外设计模块边界基于 Pinia 按领域拆分 Store 并制定状态变更约束
服务端渲染水合成本传统 SSR 首屏水合在低端设备上存在初始化耗时结合 Vue 3.5 Lazy Hydration 及后续 Vapor Mode 演进优化
国际化生态丰富度英文社区与部分海外三方生态规模略逊于 React优先查阅官方中英文文档与核心生态仓库

离线实测 Proxy 响应式、useCounter 组合式函数、内置组件、生命周期钩子与 TS/Tree-shaking 解析

python · 阅读源码
"""Offline Playwright Chromium verification for Vue 3 Ch02 (introduction)."""
import json
import re
from playwright.sync_api import sync_playwright


def launch_browser(p):
    for kwargs in (
        dict(headless=True),
        dict(headless=True, channel="chrome"),
        dict(headless=True, channel="msedge"),
    ):
        try:
            return p.chromium.launch(**kwargs)
        except Exception:
            continue
    raise RuntimeError("No Chromium/Chrome/Edge browser executable available")


def case_proxy_vs_defineproperty_reactivity(page):
    html = """<!doctype html>
<html><head><meta charset="utf-8"></head><body>
<script>
  const dpLogs = [];
  const vue2Obj = {};
  let _name = "Vue2";
  Object.defineProperty(vue2Obj, "name", {
    get() { return _name; },
    set(v) { _name = v; dpLogs.push(`name=${v}`); }
  });
  vue2Obj.name = "Vue2-updated";
  vue2Obj.email = "new@example.com";
  const dpArr = ["vue", "ts"];
  dpArr[0] = "vue2";

  const proxyLogs = [];
  function reactive(obj) {
    return new Proxy(obj, {
      get(target, key, receiver) {
        const res = Reflect.get(target, key, receiver);
        return (res && typeof res === "object") ? reactive(res) : res;
      },
      set(target, key, value, receiver) {
        const prev = target[key];
        const ok = Reflect.set(target, key, value, receiver);
        if (prev !== value) proxyLogs.push(`${String(key)}=${value}`);
        return ok;
      }
    });
  }
  function ref(init) {
    const watchers = [];
    let _val = init;
    return {
      get value() { return _val; },
      set value(v) {
        const oldVal = _val;
        _val = v;
        watchers.forEach((cb) => cb(v, oldVal));
      },
      _watch(cb) { watchers.push(cb); }
    };
  }
  const user = reactive({ name: "BlueSky", age: 18, skills: ["vue", "typescript"] });
  user.email = "dev@example.com";
  user.skills[0] = "vue3";

  const count = ref(0);
  const watchEvents = [];
  count._watch((newVal, oldVal) => watchEvents.push(`${oldVal}->${newVal}`));
  count.value = 10;

  window.__res = {
    definePropertyTracked: dpLogs,
    definePropertyMissedEmail: !dpLogs.some((s) => s.startsWith("email=")),
    proxyTracked: proxyLogs,
    userEmail: user.email,
    firstSkill: user.skills[0],
    watchEvents
  };
</script>
</body></html>"""
    page.set_content(html)
    actual = page.evaluate("window.__res")
    expected = {
        "definePropertyTracked": ["name=Vue2-updated"],
        "definePropertyMissedEmail": True,
        "proxyTracked": ["email=dev@example.com", "0=vue3"],
        "userEmail": "dev@example.com",
        "firstSkill": "vue3",
        "watchEvents": ["0->10"],
    }
    return dict(name="proxy_vs_defineproperty_reactivity", expected=expected, actual=actual, passed=(actual == expected))


def case_composition_api_and_composable(page):
    html = """<!doctype html>
<html><head><meta charset="utf-8"></head><body>
  <div id="app1"></div>
  <div id="app2"></div>
  <script>
    function ref(init) {
      const subs = new Set();
      let _v = init;
      return {
        get value() { return _v; },
        set value(v) { _v = v; subs.forEach((f) => f()); },
        _sub(fn) { subs.add(fn); }
      };
    }
    function useCounter(initialValue = 0) {
      const count = ref(initialValue);
      const doubled = () => count.value * 2;
      const increment = () => { count.value++; };
      const decrement = () => { count.value--; };
      const reset = () => { count.value = initialValue; };
      return { count, doubled, increment, decrement, reset };
    }
    function createApp(initial) {
      const api = useCounter(initial);
      return {
        api,
        mount(sel) {
          const el = document.querySelector(sel);
          const render = () => { el.textContent = `count=${api.count.value},doubled=${api.doubled()}`; };
          api.count._sub(render);
          render();
          return api;
        }
      };
    }
    const vm1 = createApp(10).mount("#app1");
    const vm2 = createApp(0).mount("#app2");
    vm1.increment();
    vm1.increment();
    const afterInc = document.getElementById("app1").textContent;
    vm1.decrement();
    const afterDec = document.getElementById("app1").textContent;
    vm1.reset();
    const afterReset = document.getElementById("app1").textContent;
    vm2.increment();
    window.__res = {
      afterInc,
      afterDec,
      afterReset,
      app2Isolated: document.getElementById("app2").textContent
    };
  </script>
</body></html>"""
    page.set_content(html)
    actual = page.evaluate("window.__res")
    expected = {
        "afterInc": "count=12,doubled=24",
        "afterDec": "count=11,doubled=22",
        "afterReset": "count=10,doubled=20",
        "app2Isolated": "count=1,doubled=2",
    }
    return dict(name="composition_api_and_composable", expected=expected, actual=actual, passed=(actual == expected))


def case_fragment_teleport_suspense_dom(page):
    html = """<!doctype html>
<html><head><meta charset="utf-8"></head><body>
  <section id="frag-host"></section>
  <div id="clipped-parent" style="overflow:hidden; position:relative; z-index:1;">
    <button id="open-modal">打开弹窗</button>
  </div>
  <div id="suspense-host"></div>
  <script>
    const frag = document.createDocumentFragment();
    const h = document.createElement("header"); h.textContent = "头部节点";
    const m = document.createElement("main"); m.textContent = "主体节点";
    frag.append(h, m);
    document.getElementById("frag-host").appendChild(frag);

    document.getElementById("open-modal").addEventListener("click", () => {
      const modal = document.createElement("div");
      modal.id = "teleported-modal";
      modal.textContent = "全局弹窗";
      document.body.appendChild(modal);
    });

    const sHost = document.getElementById("suspense-host");
    sHost.innerHTML = '<div class="loading">加载中...</div>';
    window.__fallbackText = sHost.textContent.trim();
    window.__resolveAsync = () => new Promise((resolve) => {
      setTimeout(() => {
        sHost.innerHTML = '<div class="profile">异步用户资料已就绪</div>';
        resolve(sHost.textContent.trim());
      }, 20);
    });
  </script>
</body></html>"""
    page.set_content(html)
    page.click("#open-modal")
    resolved_text = page.evaluate("window.__resolveAsync()")
    actual = page.evaluate(
        """() => ({
            fragmentChildren: Array.from(document.getElementById('frag-host').children).map(e => e.tagName),
            modalParentTag: document.getElementById('teleported-modal').parentElement.tagName,
            insideClippedParent: document.getElementById('clipped-parent').contains(document.getElementById('teleported-modal')),
            fallbackText: window.__fallbackText
        })"""
    )
    actual["resolvedText"] = resolved_text
    expected = {
        "fragmentChildren": ["HEADER", "MAIN"],
        "modalParentTag": "BODY",
        "insideClippedParent": False,
        "fallbackText": "加载中...",
        "resolvedText": "异步用户资料已就绪",
    }
    return dict(name="fragment_teleport_suspense_dom", expected=expected, actual=actual, passed=(actual == expected))


def case_lifecycle_hooks_sequence(page):
    html = """<!doctype html>
<html><head><meta charset="utf-8"></head><body>
  <div id="lc-root"></div>
  <script>
  (() => {
    const log = [];
    let count = 0;
    let timer = null;
    const root = document.getElementById("lc-root");
    function mountComponent() {
      log.push("setup");
      log.push("onBeforeMount");
      root.textContent = `已运行:${count} 秒`;
      log.push("onMounted");
      timer = setInterval(() => { count++; }, 15);
    }
    function updateComponent(nextCount) {
      log.push("onBeforeUpdate");
      count = nextCount;
      root.textContent = `已运行:${count} 秒`;
      log.push("onUpdated");
    }
    function unmountComponent() {
      log.push("onBeforeUnmount");
      clearInterval(timer);
      timer = null;
      root.textContent = "";
      log.push("onUnmounted");
    }
    mountComponent();
    updateComponent(1);
    unmountComponent();
    const countAfterUnmount = count;
    window.__checkAfterWait = () => new Promise((resolve) => {
      setTimeout(() => resolve({ log, countStableAfterUnmount: count === countAfterUnmount, cleared: timer === null }), 40);
    });
  })();
  </script>
</body></html>"""
    page.set_content(html)
    actual = page.evaluate("window.__checkAfterWait()")
    expected = {
        "log": [
            "setup",
            "onBeforeMount",
            "onMounted",
            "onBeforeUpdate",
            "onUpdated",
            "onBeforeUnmount",
            "onUnmounted",
        ],
        "countStableAfterUnmount": True,
        "cleared": True,
    }
    return dict(name="lifecycle_hooks_sequence", expected=expected, actual=actual, passed=(actual == expected))


def case_ts_sfc_and_treeshaking_analysis():
    all_vue_exports = [
        "ref", "reactive", "computed", "watch", "watchEffect",
        "nextTick", "onMounted", "onUnmounted", "provide", "inject",
    ]
    import_stmt = "import { ref, computed, watch, nextTick, onMounted } from 'vue'"
    m = re.search(r"import\s*\{([^}]+)\}\s*from\s*'vue'", import_stmt)
    imported = [tok.strip() for tok in m.group(1).split(",") if tok.strip()]
    shaken = [name for name in all_vue_exports if name not in imported]

    ts_sfc = """<script setup lang="ts">
import { ref, computed } from 'vue'
interface User { id: number; name: string; email?: string }
const user = ref<User>({ id: 1, name: 'BlueSky' })
const props = defineProps<{ title: string; count?: number }>()
const emit = defineEmits<{ (e: 'update', value: number): void; (e: 'close'): void }>()
const displayName = computed(() => user.value.name.toUpperCase())
</script>"""
    lang = re.search(r'<script\s+setup\s+lang="([^"]+)">', ts_sfc).group(1)
    iface = re.search(r"interface\s+(\w+)", ts_sfc).group(1)
    has_props_macro = "defineProps<" in ts_sfc
    has_emits_macro = "defineEmits<" in ts_sfc

    actual = {
        "retained_count": len(imported),
        "shaken_count": len(shaken),
        "script_lang": lang,
        "interface_name": iface,
        "typed_macros": [has_props_macro, has_emits_macro],
    }
    expected = {
        "retained_count": 5,
        "shaken_count": 5,
        "script_lang": "ts",
        "interface_name": "User",
        "typed_macros": [True, True],
    }
    return dict(name="ts_sfc_and_treeshaking_analysis", expected=expected, actual=actual, passed=(actual == expected))


def main():
    with sync_playwright() as p:
        browser = launch_browser(p)
        try:
            page = browser.new_page()
            cases = [
                case_proxy_vs_defineproperty_reactivity(page),
                case_composition_api_and_composable(page),
                case_fragment_teleport_suspense_dom(page),
                case_lifecycle_hooks_sequence(page),
                case_ts_sfc_and_treeshaking_analysis(),
            ]
        finally:
            browser.close()
    print(json.dumps({"cases": cases}, ensure_ascii=False))


if __name__ == "__main__":
    main()
预期结果 · 待实际运行核验
  • 核对 Proxy 监听新增属性与数组索引、useCounter 状态递增/重置与多实例隔离、Fragment/Teleport/Suspense 真实 DOM 行为、7 步生命周期顺序及定时器清理、以及 5/10 具名导入裁剪与 TS SFC 宏识别。
离线实测 Proxy 响应式、useCounter 组合式函数、内置组件、生命周期钩子与 TS/Tree-shaking 解析

所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

当前源码 SHA256:80f10833667c7cf71dca6c8d49843fa15f9d9dce4e6ef5d97cdee372a86b1b51

下载本站示例源码

本地运行

解压后按 README 说明在对应本地环境运行脚本。

下载Vue3 简介实验

所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

ZIP SHA256:cf0becfc10fe9c6d25a5a6ce2bf717e96dab6d2c6829f93ce071dfde4444fb67

常见错误与边界

  • 实际端口、文档资源与应用配置都应和测试条件一致。

练习与解答

为什么 Vue 3 使用 Proxy 替代 Object.defineProperty 后可以原生监听新增属性和数组索引赋值?Teleport 解决了什么 CSS 渲染难题?

展开参考解答

Object.defineProperty 只能在初始化时针对已有属性劫持 getter/setter,无法拦截后来新增的键和数组下标赋值;Proxy 直接代理整个对象与数组操作,天然捕获任意属性读写。Teleport 将弹窗等子树挂载到 body 等目标容器,避免被父元素的 overflow:hidden 或局部 z-index 层叠上下文裁剪。

规范与官方依据