vue3知识点(五)--teleport

2022-01-23  本文已影响0人  Amy_yqh
<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>
上一篇 下一篇

猜你喜欢

热点阅读