首页  >  文章  >  web前端  >  vue中dialog弹框如何实现

vue中dialog弹框如何实现

亚连
亚连原创
2018-06-04 15:35:432879浏览

下面我就为大家分享一篇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(&#39;on-close&#39;)
  }
 }
 }
</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__的关系详解

Node.JS循环删除非空文件夹及子目录下的所有文件

js中document.write和document.writeln的区别

以上是vue中dialog弹框如何实现的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn