当前位置:Gxlcms > JavaScript > vue中dialog弹框如何实现

vue中dialog弹框如何实现

时间:2021-07-01 10:21:17 帮助过:67人阅读

下面我就为大家分享一篇vue中简单弹框dialog的实现方法,具有很好的参考价值,希望对大家有所帮助。

效果如下,dialog中内容自行添加

  1. <template>
  2. <p>
  3. <p class="dialog-wrap">
  4. <p class="dialog-cover" v-if="isShow" @click="closeMyself"></p>
  5. <transition name="drop">
  6. <p class="dialog-content" v-if="isShow">
  7. <p class="dialog-close" @click="closeMyself">x</p>
  8. <slot>empty</slot>
  9. </p>
  10. </transition>
  11. </p>
  12. </p>
  13. </template>

接收父组件传参isShow,并返回一个自定义事件on-close

  1. <script>
  2. export default {
  3. props: {
  4. isShow: {
  5. type: Boolean,
  6. default: false
  7. }
  8. },
  9. data () {
  10. return {
  11. }
  12. },
  13. methods: {
  14. closeMyself () {
  15. this.$emit('on-close')
  16. }
  17. }
  18. }
  19. </script>
  1. <style scoped>
  2. .drop-enter-active {
  3. transition: all .5s ease;
  4. }
  5. .drop-leave-active {
  6. transition: all .3s ease;
  7. }
  8. .drop-enter {
  9. transform: translateY(-500px);
  10. }
  11. .drop-leave-active {
  12. transform: translateY(-500px);
  13. }
  14. .dialog-wrap {
  15. position: fixed;
  16. width: 100%;
  17. height: 100%;
  18. }
  19. .dialog-cover {
  20. background: #000;
  21. opacity: .3;
  22. position: fixed;
  23. z-index: 5;
  24. top: 0;
  25. left: 0;
  26. width: 100%;
  27. height: 100%;
  28. }
  29. .dialog-content {
  30. width: 50%;
  31. position: fixed;
  32. max-height: 50%;
  33. overflow: auto;
  34. background: #fff;
  35. top: 20%;
  36. left: 50%;
  37. margin-left: -25%;
  38. z-index: 10;
  39. border: 2px solid #464068;
  40. padding: 2%;
  41. line-height: 1.6;
  42. }
  43. .dialog-close {
  44. position: absolute;
  45. right: 5px;
  46. top: 5px;
  47. width: 20px;
  48. height: 20px;
  49. text-align: center;
  50. cursor: pointer;
  51. }
  52. .dialog-close:hover {
  53. color: #4fc08d;
  54. }
  55. </style>

上面是我整理给大家的,希望今后会对大家有帮助。

相关文章:

Javascript中prototype与__proto__的关系详解

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

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

以上就是vue中dialog弹框如何实现的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行