下面我就為大家分享一篇vue中簡單彈框dialog的實作方法,具有很好的參考價值,希望對大家有幫助。
效果如下,dialog中內容自行加入
<template> <p> <p class="dialog-wrap"> <p class="dialog-cover" v-if="isShow" @click="closeMyself"></p> <transition name="drop"> <p class="dialog-content" v-if="isShow"> <p class="dialog-close" @click="closeMyself">x</p> <slot>empty</slot> </p> </transition> </p> </p> </template>
接收父元件傳參isShow,並傳回一個自訂事件on-close
<script> export default { props: { isShow: { type: Boolean, default: false } }, data () { return { } }, methods: { closeMyself () { this.$emit('on-close') } } } </script>
<style scoped> .drop-enter-active { transition: all .5s ease; } .drop-leave-active { transition: all .3s ease; } .drop-enter { transform: translateY(-500px); } .drop-leave-active { transform: translateY(-500px); } .dialog-wrap { position: fixed; width: 100%; height: 100%; } .dialog-cover { background: #000; opacity: .3; position: fixed; z-index: 5; top: 0; left: 0; width: 100%; height: 100%; } .dialog-content { width: 50%; position: fixed; max-height: 50%; overflow: auto; background: #fff; top: 20%; left: 50%; margin-left: -25%; z-index: 10; border: 2px solid #464068; padding: 2%; line-height: 1.6; } .dialog-close { position: absolute; right: 5px; top: 5px; width: 20px; height: 20px; text-align: center; cursor: pointer; } .dialog-close:hover { color: #4fc08d; } </style>
上面是我整理給大家的,希望未來會對大家有幫助。
相關文章:
Javascript中prototype與__proto__的關係詳解
js中document.write和document.writeln的差異
以上是vue中dialog彈框如何實現的詳細內容。更多資訊請關注PHP中文網其他相關文章!