vueJS 008 遍历

1. 插值
<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue2.6.11.js"></script>
    <style type="text/css">

    </style>
</head>
<body>
<div id="app">
    <div>{{nums[0]}}</div>
    <div>{{nums[1]}}</div>
    <div>{{nums[2]}}</div>
</div>
<script>
    var vm = new Vue({
        el: '#app',
        data:{
            nums:[1,2,3]
        }
    });
</script>
</body>
</html>
2. v-for
<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue2.6.11.js"></script>
    <style type="text/css">

    </style>
</head>
<body>
<div id="app">
    <div v-for="(v,i) in nums">{{i}} 个数字:{{v}}</div>
</div>
<script>
    var vm = new Vue({
        el: '#app',
        data:{
            nums:[1,2,3]
        }
    });
</script>
</body>
</html>
3. 嵌套循环
<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue2.6.11.js"></script>
    <style type="text/css">

    </style>
</head>
<body>
<div id="app">
    <div v-for="(v,i) in plants">
        <div v-for="(val,key,n) in v">键:{{key}} , 值: {{val}} , 角标:{{n}}</div>
    </div>
</div>
<script>
    var vm = new Vue({
        el: '#app',
        data:{
            plants:[
                {id:1,name:"百山祖冷杉",survive:"已灭绝"}
                ,{id:2,name:"普陀鹅耳枥",survive:"已灭绝"}
            ]
        }
    });
</script>
</body>
</html>
4 . 指定循环次数
<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue2.6.11.js"></script>
    <style type="text/css">
        button{
            height: 37px;
            width: 100px;
        }
    </style>
</head>
<body>
<div id="app">
    <div v-for="counter in 5">
        <button>{{counter}}</button>
    </div>
</div>
<script>
    var vm = new Vue({
        el: '#app'
    });
</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值