basic-usage.vue 956 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <el-button text @click="dialogVisible = true">
  3. click to open the Dialog
  4. </el-button>
  5. <el-dialog
  6. v-model="dialogVisible"
  7. title="Tips"
  8. width="30%"
  9. :before-close="handleClose"
  10. >
  11. <span>This is a message</span>
  12. <template #footer>
  13. <span class="dialog-footer">
  14. <el-button @click="dialogVisible = false">Cancel</el-button>
  15. <el-button type="primary" @click="dialogVisible = false">
  16. Confirm
  17. </el-button>
  18. </span>
  19. </template>
  20. </el-dialog>
  21. </template>
  22. <script lang="ts" setup>
  23. import { ref } from 'vue'
  24. import { ElMessageBox } from 'element-plus'
  25. const dialogVisible = ref(false)
  26. const handleClose = (done: () => void) => {
  27. ElMessageBox.confirm('Are you sure to close this dialog?')
  28. .then(() => {
  29. done()
  30. })
  31. .catch(() => {
  32. // catch error
  33. })
  34. }
  35. </script>
  36. <style scoped>
  37. .dialog-footer button:first-child {
  38. margin-right: 10px;
  39. }
  40. </style>