Vue Recursive component subcomponents cannot read item

clipboard.png
cannot read item.children; in < second-stage > but can read it in {{item.children}}. What is the reason for this? Thank you, boss

Mar.19,2021

from the screenshot, each item in your data should not have a children attribute at the beginning, that is, item.children is undefined , so the evaluation of item.children.length in v-if will report an error, so the second-stage in v-if may not.

{{item.children}} can be because it is empty at first, and then there is data, which is the data, and no error is raised in this process.

you try to replace the judgment sentence of v-if with:

v-if="item.children && item.children.length"

eliminate the error first.

The data structure of

data should be problematic


item.children type

Menu