父组件 ( 正常引入调用 )

<template>
    <div>
        <moduleSun :chartData="item" v-for="(item,index) in chartData" :key="index" />
    </div>
</template>

<script>
import moduleSun from '@/views/moduleSun'
export default {
    components: { moduleSun },
    data() {
        return {
            chartData: [{
                nameCN: '111',
                nameEN: 'en111',
                remarks: '我是111',
                children: [{
                    nameCN: '222',
                    nameEN: 'en222',
                    remarks: '我是222',
                    children: [{
                        nameCN: '222-111',
                        nameEN: 'en222-111',
                        remarks: '我是222-111',
                    }],
                }, {
                    nameCN: '333',
                    nameEN: 'en333',
                    remarks: '我是333',
                }],
            }],
        }
    },
}
</script>

子组件 ( 组件中需定义name名称 )

<template>
    <div class="chart-layout">
        <div class="chart-main">
            <div>{{chartData.nameCN}}</div>
            <div class="chart-en">{{chartData.nameEN}}</div>
            <div class="chart-remarks">{{chartData.remarks}}</div>
        </div>
        <moduleSun :chartData="item" v-for="(item,index) in chartData.children" :key="index" />
    </div>
</template>

<script>
export default {
    name: 'moduleSun',
    props: {
        chartData: {
            type: Object,
            default: () => {
                return {}
            }
        },
    },
}
</script>

<style lang="less" scoped>
.chart-main {
    width: 100px;
    border: 1px solid #000;

    > div {
        margin-top: 5px;
    }
}
</style>

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐