用@click写个基于vue的弹窗
时间: 2023-05-19 21:07:20 浏览: 90
当然可以,以下是一个基于Vue的弹窗组件的代码示例:
<template>
<div>
<button @click="showModal = true">打开弹窗</button>
<div v-if="showModal" class="modal">
<div class="modal-content">
<span class="close" @click="showModal = false">×</span>
<h2>这是一个弹窗</h2>
<p>你可以在这里添加任何内容</p>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
showModal: false
};
}
};
</script>
<style>
.modal {
display: block;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
</style>
请注意,这只是一个简单的示例,你可以根据自己的需求进行修改和扩展。