mDialog.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <el-dialog
  3. custom-class="dialog-custom"
  4. :title="$slots.title ? '' : title"
  5. :visible.sync="visible"
  6. :width="width"
  7. :top="top"
  8. :append-to-body="true"
  9. :modal="modal"
  10. :close-on-click-modal="false"
  11. :fullscreen="false"
  12. :destroy-on-close="false"
  13. :modal-append-to-body="true"
  14. :before-close="handleClose"
  15. v-dialogDrag
  16. center
  17. @open="open"
  18. @opened="opened"
  19. @close="close"
  20. @closed="closed"
  21. >
  22. <template v-if="$slots.title">
  23. <span slot="title">
  24. <slot name="title" />
  25. </span>
  26. </template>
  27. <slot />
  28. <span slot="footer" class="dialog-footer">
  29. <slot name="footer" />
  30. </span>
  31. </el-dialog>
  32. </template>
  33. <script>
  34. export default {
  35. name: "mDialog",
  36. props: {
  37. show: {
  38. type: Boolean,
  39. default: false,
  40. },
  41. title: {
  42. type: String,
  43. default: "提示",
  44. },
  45. modal: {
  46. // 是否需要遮罩层
  47. type: Boolean,
  48. default: true,
  49. },
  50. width: {
  51. type: String,
  52. default: "30%",
  53. },
  54. top: {
  55. type: String,
  56. default: "15vh"
  57. }
  58. },
  59. computed: {
  60. visible: {
  61. get() {
  62. return this.show;
  63. },
  64. set(val) {
  65. this.$emit("update:show", val); // visible 改变的时候通知父组件
  66. },
  67. },
  68. },
  69. data() {
  70. return {};
  71. },
  72. methods: {
  73. // 关闭前回调
  74. handleClose(done) {
  75. this.$emit("beforeClose");
  76. done();
  77. },
  78. // Dialog 打开的回调
  79. open() {
  80. this.$emit("open");
  81. },
  82. // Dialog 打开动画结束时的回调
  83. opened() {
  84. this.$emit("opened");
  85. },
  86. // Dialog 关闭的回调
  87. close() {
  88. this.$emit("close");
  89. },
  90. // Dialog 关闭动画结束时的回调
  91. closed() {
  92. this.$emit("closed");
  93. },
  94. },
  95. };
  96. </script>
  97. <style scoped lang="scss">
  98. // .dialog-custom{
  99. // .el-dialog__header{
  100. // }
  101. // }
  102. </style>