美文网首页
vue3知识点(五)--teleport

vue3知识点(五)--teleport

作者: Amy_yqh | 来源:发表于2022-01-23 12:29 被阅读0次
<template>
    <div>
        <button @click="modalOpen = true">弹出一个模块窗口</button>
        <teleport to="body">
            <div v-if="modalOpen" class="modal">
                <div>
                    我是一个模块框
                    <button @click="modalOpen = false">关闭</button>
                </div>
            </div>
        </teleport>
    </div>
    
</template>

<script>
import {ref} from 'vue'
export default {
    setup(){
        let modalOpen = ref(false)
        return{
            modalOpen
        }
    }
}
</script>

<style scoped>
.modal{
    position: absolute;
    background-color: rgba(0,0,0,.5);
    top:0;
    bottom:0;
    right:0;
    left:0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.modal div{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    width:300px;
    height: 300px;
    padding:5px;
}
</style>

相关文章

网友评论

      本文标题:vue3知识点(五)--teleport

      本文链接:https://www.haomeiwen.com/subject/jesmhrtx.html