distinguishable-close-cancel.vue 848 B

12345678910111213141516171819202122232425262728293031323334
  1. <template>
  2. <el-button text @click="open">Click to open Message Box</el-button>
  3. </template>
  4. <script lang="ts" setup>
  5. import { ElMessage, ElMessageBox } from 'element-plus'
  6. import type { Action } from 'element-plus'
  7. const open = () => {
  8. ElMessageBox.confirm(
  9. 'You have unsaved changes, save and proceed?',
  10. 'Confirm',
  11. {
  12. distinguishCancelAndClose: true,
  13. confirmButtonText: 'Save',
  14. cancelButtonText: 'Discard Changes',
  15. }
  16. )
  17. .then(() => {
  18. ElMessage({
  19. type: 'info',
  20. message: 'Changes saved. Proceeding to a new route.',
  21. })
  22. })
  23. .catch((action: Action) => {
  24. ElMessage({
  25. type: 'info',
  26. message:
  27. action === 'cancel'
  28. ? 'Changes discarded. Proceeding to a new route.'
  29. : 'Stay in the current route',
  30. })
  31. })
  32. }
  33. </script>