basic-usage.vue 2.0 KB

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