Vue + ts 深層次(無限)循環

1.父組件:
<template>
<div class="balance">
<son :item="chartData"></son>
</div>
</template>

<script lang="ts">
import { Component,Vue } from "vue-property-decorator";
import son from './son.vue'

@Component({
components: {son}
})

2.子組件
<template>
<div class="son">
<ul v-for="item in item" :key="item.index">
<li>{{ item.name }}</li>
<ul v-if="item.children">
<son :item="item.children"></son>
</ul>
</ul>
</div>
</template>
<script lang="ts">
import { Component, Vue, Prop } from "vue-property-decorator";
@Component({})
export default class son extends Vue {
@Prop(Array) item!: [];
mounted() {
this.item;
console.log(this.item);
}
}
</script>

效果:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章