Recursion in single file components in Vue.js 3
P粉710478990
P粉710478990 2023-11-23 09:54:24
0
2
636

How to use recursive components in Vue3?

Using recursive components like normal components in Vue 3 will result in errors Cannot be accessed before initialization

Tree.vue:

<template>
  <Tree v-if="hasChildren" />
</template>

<script lang="ts">
import Tree from './Tree.vue';

export default defineComponent({
  components: {
    Tree
  },

  setup() {

    const hasChildren = someExitRecursionCondition();

    return {
      hasChildren
    }
  }
</script>


P粉710478990
P粉710478990

reply all(2)
P粉176151589

You can provide only the component name option:



sssccc

P粉330232096

document:

Components can be imported by their filename, but do not need to be listed in the components settings object. However, it is enough to use the named component in the template without importing it.

Tree.vue:



sssccc
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template