28.vue3学习篇- teleport

在 Vue 3 中,<Teleport>是一个强大的功能,它允许你将一个组件的模板内容渲染到 DOM 中的不同位置,而不是在该组件的父级组件的 DOM 层级中渲染。

以下是一个基本的使用示例:

// src/dialog.vue 公共弹窗

<template>
    <div class="portals">
        <button @click="ShowNotification">trigger Notification</button> 
        <teleport to='#portal'>
            <div v-if="isOpen" class="notification">
                this is rendering outside of this child component
            </div>
        </teleport>
    </div>
</template>

<script>
import { ref } from 'vue'
export default {
    setup () {
        const isOpen = ref(false);

        var closePopup;

        const ShowNotification = () => {
            isOpen.value = true

            clearTimeout(closePopup);

            closePopup = setTimeout(() => {
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值