teleport 传送门
作者:互联网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<script src="../js/vue.js"></script>
<style>
.area {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
width: 200px;
height: 300px;
background-color: #000;
}
.mask { position: absolute; left: 0; right: 0; top: 0; bottom: 0; background: #000; opacity: .5; } </style> </head> <body> <div id="root"></div> <script> // teleport 传送门 var app = Vue.createApp({ data(){ return { show: false } }, methods:{ handleBtnClick(){ this.show = !this.show } }, template:` <div class="area"> <button @click="handleBtnClick">按钮</button>
<teleport to="body"> <div class="mask" v-show="show"> </div> </teleport> </div> `, })
const vm = app.mount('#root')
</script>
</body> </html>
.mask { position: absolute; left: 0; right: 0; top: 0; bottom: 0; background: #000; opacity: .5; } </style> </head> <body> <div id="root"></div> <script> // teleport 传送门 var app = Vue.createApp({ data(){ return { show: false } }, methods:{ handleBtnClick(){ this.show = !this.show } }, template:` <div class="area"> <button @click="handleBtnClick">按钮</button>
<teleport to="body"> <div class="mask" v-show="show"> </div> </teleport> </div> `, })
const vm = app.mount('#root')
</script>
</body> </html>
标签:teleport,show,传送门,app,50%,absolute 来源: https://www.cnblogs.com/eric-share/p/15660173.html