vue 基础入门笔记 04:v-for
vue 基础入门笔记 04
- v-for的四种情况
- 数组
- 数组对象
- 对象
- 数字
- 在组件中key是必须的
<!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>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app">
<!-- 数组 -->
<p v-for="(item,index) in list">索引值{{index}}-------每一项{{item}}</p>
<!-- 数组对象 -->
<p v-for="(item,index) in list2">索引值{{index}}-------每一项{{item.name}}</p>
<!-- 对象 -->
<p v-for="(val,key,index) in list3">索引值{{index}}-------每一项{{val}}-----key{{key}}</p>
<!-- 数字 -->
<p v-for="count in 10">{{count}}</p>
<!-- key的属性只能是number 或者 string -->
<p v-for="count in 10" :key="count">{{count}}</p>
</div>
<script>
var vm=new Vue({
el:'#app',
data:{
list:[
'a','b','c'
],
list2:[
{'name':'aaaa'},
{'name':'bbbb'},
{'name':'cccc'},
{'name':'dddd'},
],
list3:{
name:'zs',
sex:'man',
age:20
}
},
methods:{}
});
</script>
</body>
</html>
本作品采用《CC 协议》,转载必须注明作者和本文链接