for in 和 for of 的區別和v-for指令的三種使用方法


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM