basic-usage.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <el-radio-group v-model="direction">
  3. <el-radio label="ltr">left to right</el-radio>
  4. <el-radio label="rtl">right to left</el-radio>
  5. <el-radio label="ttb">top to bottom</el-radio>
  6. <el-radio label="btt">bottom to top</el-radio>
  7. </el-radio-group>
  8. <el-button type="primary" style="margin-left: 16px" @click="drawer = true">
  9. open
  10. </el-button>
  11. <el-button type="primary" style="margin-left: 16px" @click="drawer2 = true">
  12. with footer
  13. </el-button>
  14. <el-drawer
  15. v-model="drawer"
  16. title="I am the title"
  17. :direction="direction"
  18. :before-close="handleClose"
  19. >
  20. <span>Hi, there!</span>
  21. </el-drawer>
  22. <el-drawer v-model="drawer2" :direction="direction">
  23. <template #header>
  24. <h4>set title by slot</h4>
  25. </template>
  26. <template #default>
  27. <div>
  28. <el-radio v-model="radio1" label="Option 1" size="large"
  29. >Option 1</el-radio
  30. >
  31. <el-radio v-model="radio1" label="Option 2" size="large"
  32. >Option 2</el-radio
  33. >
  34. </div>
  35. </template>
  36. <template #footer>
  37. <div style="flex: auto">
  38. <el-button @click="cancelClick">cancel</el-button>
  39. <el-button type="primary" @click="confirmClick">confirm</el-button>
  40. </div>
  41. </template>
  42. </el-drawer>
  43. </template>
  44. <script lang="ts" setup>
  45. import { ref } from 'vue'
  46. import { ElMessageBox } from 'element-plus'
  47. const drawer = ref(false)
  48. const drawer2 = ref(false)
  49. const direction = ref('rtl')
  50. const radio1 = ref('Option 1')
  51. const handleClose = (done: () => void) => {
  52. ElMessageBox.confirm('Are you sure you want to close this?')
  53. .then(() => {
  54. done()
  55. })
  56. .catch(() => {
  57. // catch error
  58. })
  59. }
  60. function cancelClick() {
  61. drawer2.value = false
  62. }
  63. function confirmClick() {
  64. ElMessageBox.confirm(`Are you confirm to chose ${radio1.value} ?`)
  65. .then(() => {
  66. drawer2.value = false
  67. })
  68. .catch(() => {
  69. // catch error
  70. })
  71. }
  72. </script>