basic-usage.vue 987 B

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