Home >Web Front-end >JS Tutorial >How to implement dialog pop-up box in vue

How to implement dialog pop-up box in vue

亚连
亚连Original
2018-06-04 15:35:432934browse

Below I will share with you an implementation method of a simple pop-up dialog in Vue. It has a good reference value and I hope it will be helpful to everyone.

The effect is as follows, the content in the dialog is added by itself

<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>

Receives the parameter isShow from the parent component and returns a custom event 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>

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Detailed explanation of the relationship between prototype and __proto__ in Javascript

Node.JS loops to delete non-empty folders and All files in the subdirectory

The difference between document.write and document.writeln in js

The above is the detailed content of How to implement dialog pop-up box in vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn