<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>lesson 30 teleport</title>
<script src="https://unpkg.com/vue@next"></script>
<style>
.area {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
width: 200px;
height: 300px;
background: #000000;
}
.mask {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: #000000;
opacity: .5;
}
</style>
</head>
<body>
<div id="root"></div>
<div id="hello"></div>
</body>
<script>
//teleport 传送门语法
//teleport 可以将元素属性传输到别的元素上去渲染
const 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">123</div>
</teleport>
</div>
`
});
app.mount('#root');
</script>
</html>
Vue3.0 传送门语法
最新推荐文章于 2024-05-03 16:28:39 发布