dynamic-loading.vue 583 B

123456789101112131415161718192021222324
  1. <template>
  2. <el-cascader :props="props" />
  3. </template>
  4. <script lang="ts" setup>
  5. import type { CascaderProps } from 'element-plus'
  6. let id = 0
  7. const props: CascaderProps = {
  8. lazy: true,
  9. lazyLoad(node, resolve) {
  10. const { level } = node
  11. setTimeout(() => {
  12. const nodes = Array.from({ length: level + 1 }).map((item) => ({
  13. value: ++id,
  14. label: `Option - ${id}`,
  15. leaf: level >= 2,
  16. }))
  17. // Invoke `resolve` callback to return the child nodes data and indicate the loading is finished.
  18. resolve(nodes)
  19. }, 1000)
  20. },
  21. }
  22. </script>