<template>
<div>
<!-- 触发弹窗的按钮 -->
<button @click="showModal = true">打开弹窗</button>
<!-- 弹窗组件 -->
<transition name="modal">
<div v-if="showModal" class="modal-mask">
<div class="modal-wrapper">
<div class="modal-container">
<!-- 弹窗标题 -->
<div class="modal-header">
<slot name="header">
默认标题
</slot>
</div>
<!-- 弹窗内容 -->
<div class="modal-body">
<slot name="body">
默认内容
</slot>
</div>
<!-- 弹窗底部操作 -->
<div class="modal-footer">
<slot name="footer">
<button @click="showModal = false">关闭</button>
</slot>
</div>
</div>
</div>
</div>
</transition>
</div>
</template>
<script>
export default {
data() {
return {
showModal: false, // 控制弹窗显示/隐藏的状态
};
},
};
</script>
<style>
/* 弹窗样式 */
.modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: table;
transition: opacity 0.3s ease;
}
.modal-wrapper {
display: table-cell;
vertical-align: middle;
}
.modal-container {
width: 300px;
margin: 0px auto;
padding: 20px 30px;
background-color: #fff;
border-radius: 2px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
transition: all 0.3s ease;
font-family: Helvetica, Arial, sans-serif;
}
.modal-header h3 {
margin-top: 0;
color: #42b983;
}
.modal-body {
margin: 20px 0;
}
.modal-default-button {
float: right;
}
/*
* The following styles are auto-applied to elements with
* transition="modal" when their visibility is toggled
* by Vue.js.
*
* You can easily play with the modal transition by editing
* these styles.
*/
.modal-enter {
opacity: 0;
}
.modal-leave-active {
opacity: 0;
}
.modal-enter .modal-container,
.modal-leave-active .modal-container {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
</style>
模板部分 (<template>
):
v-if
指令控制弹窗的显示状态。<slot>
) 进行自定义。脚本部分 (<script>
):
data
属性 showModal
来控制弹窗的显示和隐藏,默认为 false
(即不显示)。showModal
设置为 true
,弹窗就会显示出来;当点击关闭按钮时,将其设置为 false
,弹窗消失。样式部分 (<style>
):
上一篇:vue pathrewrite
下一篇:vue get请求传递参数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站