dialog.vue 964 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <ElDialog
  3. :title="props.title"
  4. v-model="props.visiable"
  5. :width="props.width"
  6. :height="props.height"
  7. @closed="showContent = false"
  8. >
  9. <div v-if="showContent">
  10. <component :is="props.content" ref="contentRef" />
  11. </div>
  12. <template #footer>
  13. <div class="dialog-footer">
  14. <el-button @click="props.cancel">取消</el-button>
  15. <el-button type="primary" @click="submit"> 确定 </el-button>
  16. </div>
  17. </template>
  18. </ElDialog>
  19. </template>
  20. <script lang="ts" setup>
  21. import { ElDialog, ElButton } from "element-plus";
  22. import { ref, watch } from "vue";
  23. import { props } from ".";
  24. const contentRef = ref<any>(null);
  25. const showContent = ref(false);
  26. watch(
  27. () => props.visiable,
  28. () => {
  29. if (props.visiable) {
  30. showContent.value = true;
  31. }
  32. }
  33. );
  34. const submit = async () => {
  35. try {
  36. const info = await contentRef.value.submit();
  37. props.submit(info);
  38. } catch {}
  39. };
  40. </script>