vue弹窗显示代码
在Vue中,可以使用v-if和v-show指令来控制弹窗的显示和隐藏。以下是一个简单的示例:
<template>
<div>
<button @click="showModal = true">显示弹窗</button>
<div v-if="showModal" class="modal">
<div class="modal-content">
<h3>这是一个弹窗</h3>
<p>弹窗的内容...</p>
<button @click="showModal = false">关闭弹窗</button>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
showModal: false
}
}
}
</script>
<style>
.modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
}
.modal-content {
background-color: white;
padding: 20px;
border-radius: 5px;
}
</style>
在上述代码中,我们使用了一个showModal变量来控制弹窗的显示和隐藏。点击“显示弹窗”按钮时,将showModal设置为true,弹窗会显示出来。点击弹窗内的“关闭弹窗”按钮时,将showModal设置为false,弹窗会隐藏起来
原文地址: http://www.cveoy.top/t/topic/inLw 著作权归作者所有。请勿转载和采集!