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>