modal.vue 968 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <script lang="ts" setup>
  2. import { ref } from 'vue';
  3. import { useVbenModal, VbenButton } from '@vben/common-ui';
  4. const list = ref<number[]>([]);
  5. const [Modal, modalApi] = useVbenModal({
  6. onCancel() {
  7. modalApi.close();
  8. },
  9. onConfirm() {
  10. console.log('onConfirm');
  11. },
  12. onOpenChange(isOpen) {
  13. if (isOpen) {
  14. handleUpdate(10);
  15. }
  16. },
  17. });
  18. function handleUpdate(len: number) {
  19. modalApi.setState({ loading: true });
  20. setTimeout(() => {
  21. list.value = Array.from({ length: len }, (_v, k) => k + 1);
  22. modalApi.setState({ loading: false });
  23. }, 2000);
  24. }
  25. </script>
  26. <template>
  27. <Modal title="自动计算高度">
  28. <div
  29. v-for="item in list"
  30. :key="item"
  31. class="even:bg-heavy bg-muted flex-center h-[220px] w-full"
  32. >
  33. {{ item }}
  34. </div>
  35. <template #prepend-footer>
  36. <VbenButton type="link" @click="handleUpdate(6)">
  37. 点击更新数据
  38. </VbenButton>
  39. </template>
  40. </Modal>
  41. </template>