dynamic-loading.vue 583 B

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