vue父子循环添加数据

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>循环</title>
</head>
<style>
    #div2 {
        display: inline-block;
    }
</style>

<body>
    <div id="add">
        <div id="div1" v-for="lit in list">
            <p>父亲:{{lit.name}} 年龄:{{lit.Age}} 性别:{{lit.Sex}}</p>
            <div id="div2" v-for="(lt,ind) in lit.child">
                <p v-if="lit.child.length!=0">儿子:{{lt.name}} 年龄:({{lt.Age}}岁)<span v-if="ind!=lit.child.length-1">和</span>
                </p>
            </div>
            <hr>
        </div>
    </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
    var add = new Vue({
        el: '#add',
        data: {
            list: [{
                name: '周阴婷',
                Age: '130',
                Sex: '男',
                child: [{
                    name: '小皮',
                    Age: 3
                }, {
                    name: '小油',
                    Age: 2
                }]
            }, {
                name: '洋洋',
                Age: '24',
                Sex: '男',
                child: [{
                    name: '小洋',
                    Age: 2
                }]
            }, ]
        },
    })
</script>

</html>

猜你喜欢

转载自www.cnblogs.com/msz8080/p/11752966.html
今日推荐