for...in 循環:只能獲得對象的鍵名,不能獲得鍵值
for...of 循環:允許遍歷獲得鍵值
var arr = ['red', 'green', 'blue']
for(let item in arr) {
console.log('for in item', item)
}
/*
for in item 0
for in item 1
for in item 2
*/
for(let item of arr) {
console.log('for of item', item)
}
/*
for of item red
for of item green
for of item blue
*/
總之,for...in 循環主要是為了遍歷對象而生,不適用於遍歷數組
for...of 循環可以用來遍歷數組、類數組對象,字符串、Set、Map 以及 Generator 對象
轉自:https://www.cnblogs.com/rogerwu/p/10738776.html
v-for指令的三種使用方法
1.迭代數組
id:{{item.id}}---名字:{{item.name}}---索引{{item.age}}
2.迭代對象中的屬性
{{val}}--{{key}}--{{i}}
3.迭代數字
這是第{{i}}個標簽}}
在組件中使用v-for 循環的時候,如果有問題,必須使用key指定
https://www.cnblogs.com/guomouren/p/12655638.html