<font style="color:rgb(77, 77, 77);">Teleport</font>
Vue 3.0 新特性之一。
<font style="color:rgb(77, 77, 77);">Teleport</font>
是一种能够将我们的模板渲染至指定<font style="color:rgb(77, 77, 77);">DOM</font>
节点,不受父级<font style="color:rgb(77, 77, 77);">style</font>
、<font style="color:rgb(77, 77, 77);">v-show</font>
等属性影响,但<font style="color:rgb(77, 77, 77);">data</font>
、<font style="color:rgb(77, 77, 77);">prop</font>
数据依旧能够共用的技术;类似于<font style="color:rgb(77, 77, 77);">React</font>
的<font style="color:rgb(77, 77, 77);">Portal</font>
。主要解决的问题 因为
<font style="color:rgb(77, 77, 77);">Teleport</font>
节点挂载在其他指定的<font style="color:rgb(77, 77, 77);">DOM</font>
节点下,完全不受父级<font style="color:rgb(77, 77, 77);">style</font>
样式影响
Teleport 传送组件使用 to
通过 to 属性 插入指定元素位置 to=”body” 便可以将<font style="color:rgb(77, 77, 77);">Teleport</font>
内容传送到指定位置,也可以自定义传送位置 支持 class id 等 选择器。
多个使用场景
动态控制 teleport
使用 disabled 设置为 true 则 to 属性不生效 false 则生效