【问题标题】:Recursive component using Vue class-style components使用 Vue 类样式组件的递归组件
【发布时间】:2020-08-10 22:36:09
【问题描述】:

我正在使用带有 vue-property-decorator 插件的类样式组件。 我怎样才能拥有一个递归组件并在其自身中使用组件。 我的代码如下:

<template>
<ul>
    <li>
        <div>
            {{nodeData.someData}}
        </div>
    </li>
    <li>
        <TreeNode
        v-for="item in nodeData.children"
        :key="item.id"
        ></TreeNode>
    </li>
</ul>
</template>

<script lang="ts">

import {Vue, Prop, Component, Watch} from 'vue-property-decorator';

@Component({
//error :'TreeNode' was used before it was defined.
   components:{TreeNode}
})
export default class TreeNode extends Vue {

   @Prop() nodeData?: myType;

}

</script>

在组件选项中使用 TreeNode 会导致错误:在定义之前使用了“TreeNode”。 我该如何解决?或者有什么替代方法?

【问题讨论】:

    标签: typescript vue.js


    【解决方案1】:

    没有必要:

    components:{TreeNode}
    

    只要删除它,一切都会好起来的!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-01
      • 2020-04-07
      • 2021-03-10
      • 2018-08-13
      • 1970-01-01
      • 2020-07-30
      • 2023-04-02
      • 2016-12-13
      相关资源
      最近更新 更多