1. 遍历数组
可以使用of或者in作为分隔符
users为源数据数据
第一个参数user为别名({id: '#0', name: 'a'}...)
(选用)第二个参数index为索引名
user,index可以自行取名
<template>
<div v-for="(user,index) of users" :key="index">{
{user}}</div>
<hr>
<div v-for="(user,index) in users" :key="index">{
{user}}</div>
</template>
-------------------------------------------------------------
data() {
return {
users: [
{id: '#0', name: 'a'},
{id: '#1', name: 'b'},
{id: '#2', name: 'c'},
]
}
}
2. 遍历对象
同样可以使用in或者of
person为源数据数据
第一个参数value为别名,对象属性的值(tom,2,10)
(选用)第二个参数key为对象属性名(name,age,weight)
(选用)第三个参数