vue2点击图标后弹出页面,背景变暗
时间: 2023-07-16 12:14:50 浏览: 139
可以通过以下步骤实现:
1. 在页面中添加一个遮罩层,用于变暗背景。可以使用绝对定位将其覆盖在整个页面上,并设置背景颜色和透明度。
2. 在遮罩层上添加一个弹出框,用于展示需要弹出的页面。可以使用绝对定位将其居中在页面上,并设置其宽度和高度。
3. 点击图标时,通过 Vue 的事件监听器来触发弹出框的显示。可以使用 v-show 指令或者动态绑定 class 来控制弹出框的显示和隐藏。
4. 可以通过传递参数来控制弹出框中展示的内容,例如使用 props 属性传递数据。
以下是一个简单的示例代码:
```html
<template>
<div class="container">
<div class="mask" v-show="show">
<div class="popup">
<h2>{{ title }}</h2>
<p>{{ content }}</p>
</div>
</div>
<i class="icon" @click="show = true"></i>
</div>
</template>
<script>
export default {
data() {
return {
show: false,
title: '弹出框标题',
content: '弹出框内容'
}
}
}
</script>
<style>
.container {
position: relative;
}
.mask {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
}
.popup {
width: 400px;
height: 300px;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
text-align: center;
}
.icon {
font-size: 24px;
cursor: pointer;
}
</style>
```
阅读全文