我在 Vue 中有一个工作模式,但是,模式在页面加载的瞬间加载为空,我希望它保持完全隐藏(即使在页面加载时),直到单击按钮。
我在 CSS 中使用 display:none 进行了测试,它可以在页面加载时隐藏它,但是在按下按钮时它仍然完全隐藏。我试图通过将条件样式绑定到 div 来解决这个问题,但仍然没有运气。
如何通过单击按钮保持此模式的功能,同时允许它在页面加载时显示:无?
var vm = new Vue({
el: "#app",
props: {},
data: {
showDetailModal: false,
},
methods: {
openModal() {
console.log(this.showDetailModal);
this.showDetailModal = true;
console.log(this.showDetailModal);
}
},
});
.modal-vue .overlay {
//display: none;
text-align: center;
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .5);
}
.modal-vue .modal {
//display: none;
position: relative;
width: 300px;
z-index: 9999;
margin: 0 auto;
padding: 20px 30px;
background-color: #fff;
}
.modal-vue .close {
position: absolute;
top: 10px;
right: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div @click="openModal()">
Open Modal
</div>
<div class="modal-vue" v-if="showDetailModal" :style="'display: ' + (showDetailModal ? 'block' : 'none')">
<!-- overlay to help with readability of modal -->
<div class="overlay" @click="showDetailModal = false"></div>
<!-- Modal for detail on table cell click event -->
<div class="modal" v-if="showDetailModal">
<button class="close" @click="showDetailModal = false">x</button>
<h3>Testing</h3>
</div>
</div>
</div>