其他分享
首页 > 其他分享> > Teleport 传送门基础功能

Teleport 传送门基础功能

作者:互联网

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>Document</title>
<style>
.area {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 300px;
height: 200px;
background-color: aqua;
}

.teleport {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: black;
opacity: .5;
}
</style>
<script src="https://unpkg.com/vue@next"></script>
</head>

<body>
<div id="root"></div>
<div id="teleport"></div>
</body>
<script>
const app = Vue.createApp({
data() {
return {
show: false
}
},
methods: {
handleCilck() {
this.show = !this.show;
}
},
template: `
<div class="area">
<button @click="handleCilck">点击</button>
<teleport to="#teleport">
<div class="teleport" v-show="show"></div>
</teleport>
</div>
`
});
const vm = app.mount('#root');
</script>

</html>

 

 

 

图片(通过传送门将遮罩层放到body下面的#teleport中)

 

标签:Teleport,功能,show,传送门,app,50%,absolute
来源: https://www.cnblogs.com/Peat-Whisky/p/16308683.html