vue.js如何遍历map
生活随笔
收集整理的這篇文章主要介紹了
vue.js如何遍历map
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
vue.js遍歷map的方法:vue使用【v-for】遍歷Map,代碼為【<div class="area" v-for="(item, key) of cities" :key="key">】。
【相關(guān)文章推薦:vue.js】
vue.js遍歷map的方法:
對象數(shù)據(jù)如下:
"cities": {
"A": [{
"id": 56,
"spell": "aba",
"name": "阿壩"
}, {
"id": 57,
"spell": "akesu",
"name": "阿克蘇"
}],
"B": [{
"id": 58,
"spell": "baiyin",
"name": "白銀"
}, {
"id": 59,
"spell": "bangbu",
"name": "蚌埠"
}],
"C": [{
"id": 60,
"spell": "chengdu",
"name": "成都"
}, {
"id": 61,
"spell": "cangzhou",
"name": "滄州"
}]
遍歷方法如下:
<div class="area" v-for="(item, key) of cities" :key="key">
<div class="title border-topbottom">{{key}}</div>
<div class="item-list">
<div class="item border-bottom" v-for="innerItem of item" :key="innerItem.id">{{innerItem.name}}</div>
</div>
</div>
關(guān)鍵就是 v-for="(item, key) of cities",相當(dāng)于Map結(jié)構(gòu)的 (key, value)
相關(guān)免費學(xué)習(xí)推薦:JavaScript(視頻)
總結(jié)
以上是生活随笔為你收集整理的vue.js如何遍历map的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML中必须掌握的知识点有哪些
- 下一篇: JavaScript如何禁止刷新页面