老师,能帮我看看为什么这段代码执行不了
来源:1-5 Teleport 传送门功能
weixin_慕姐4338681
2022-06-06 12:27:48
<!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>
<style>
.area {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
width: 300px;
height: 300px;
background: green;
}
.mask {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: #0000;
opacity: 0.5;
color:#fff;
font-size: 100px;
}
</style>
<script src="../vue@3.2.23.js"></script>
</head>
<body>
<div id="root"></div>
<div id="hello"></div>
</body>
<script>
const app = Vue.createApp({
data() {
return {
show:false,
message:'hello'
}
},
methods:{
handleBtnClick() {
this.show=!this.show
}
},
template:`
<div class="area">
<button @click='handleBtnClick'>按钮</button>
<teleport to='#hello'>
<div class='mask' v-show='show'>{{message}}</div>
</teleport>
</div>
`
})
const vm = app.mount('#root');
</script>
</html>1回答
好帮手慕慕子
2022-06-06
同学你好,代码是没有问题的,因为遮罩层的背景颜色值使用十六进制简写方式,第四个位置的数值表示透明度,设置为0表示透明度为0, 而文字又是白色,所以看不到效果,导致同学误以为代码执行不了。
建议修改:修改背景颜色为#000

祝学习愉快~
相似问题