要使用item时必须要在被绑定了v-for属性元素的包裹之下
犯的错误:
<template>
<div>
<div class="wrapper">
<div class="detail-list" v-for="(item, index) of list" :key="index">
{{item.title}}
</div>
<div v-if="item.children"> //不在绑定v-for属性的元素内
<detail-list :list="item.children"></detail-list>
</div>
</div>
</div>
</template>
正确写法:
<template>
<div>
<div class="wrapper" v-for="(item, index) of list" :key="index">
<div class="detail-list">
{{item.title}}
</div>
<div v-if="item.children">
<detail-list :list="item.children"></detail-list>
</div>
</div>
</div>
</template>