如何在Vue3中使用递归组件?
在 Vue 3 中像普通组件一样使用递归组件会导致错误 初始化前无法访问
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>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您可以仅提供组件名称选项:
文档:
组件可以通过其文件名导入,但无需在
components设置对象中列出。不过,在模板中使用命名组件就足够了,无需导入它。Tree.vue: