问题如图所示,如何才能做到遮罩整个页面,目前只能遮罩到使用弹窗的子组件中
Modal.vue
<template>
<transition name="modal">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-container">
<div class="modal-header">
<slot name="header">
default header
</slot>
</div>
<div class="modal-body">
<slot name="body">
default body
</slot>
</div>
<div class="modal-footer">
<slot name="footer">
default footer
<button class="modal-default-button" @click="$emit('close')">
OK
</button>
</slot>
</div>
</div>
</div>
</div>
</transition>
</template>
<script>
import Vue from 'vue'
export default {
}
</script>
<style rel="stylesheet/scss" lang="scss">
.modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .5);
display: table;
transition: opacity .3s ease;
}
/*垂直居中*/
.modal-wrapper {
display: table-cell;
vertical-align: middle;
}
.modal-container {
width: 80%;
height: calc(100vh - 38px * 2);
margin: 0 auto;
margin-top: 100px;
padding: 20px 30px;
background-color: #fff;
border-radius: 2px;
box-shadow: 0 2px 8px rgba(0, 0, 0, .33);
transition: all .3s ease;
}
.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>
<div>
//页面主内容。。。
<modal v-if="showModal" @close="showModal = false">
<div slot="body">
<p>123</p>
<p>fsf</p>
<p>12fsdfds3</p>
<p>1vcxv23</p>
<p>1vxcv23</p>
</div>
</modal>
</div>
</template>
整个页面结构
<template>
<div>
<navbar :show="showNavBar" :title="title"></navbar>
<sidebar v-on:onItemClick="clickItem($event)" :show="showSideBar"></sidebar>
<app-main></app-main>
<!--<fab></fab>-->
</div>
</template>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…